0
<?php
$string = "qwertyuiopasdfghjklzxcvbnm";
$string = explode("", $string);
sort($string);
foreach ($string as $val) {
    echo $val."<br>";
}
?>

I want this to output: a b c ... but how?

1 Answer 1

6

Your current call to explode() isn't working -- it doesn't accept an empty first argument. Try using str_split() instead:

$string = "qwertyuiopasdfghjklzxcvbnm";
$array = str_split($string, 1);
sort($array);
foreach ($array as $val) {
    echo $val."<br>";
}
Sign up to request clarification or add additional context in comments.

Comments

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.