0

I want to sort stuff while looping

$arr = array('c','a''b');
 foreach($arr as $alpha){
  sort($alpha);
  echo $alpha."-";
 }

and it should end up with a-b-c
how to get it done ?

1 Answer 1

4
$arr = array('c','a', 'b');
sort($arr);
foreach($arr as $alpha) {
    echo $alpha . "-";
}

Sort only needs to be called once.

Sign up to request clarification or add additional context in comments.

1 Comment

And for printing use implode instead of looping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.