Sorting a array in alphabetical order in php?
<?php
$string =开发者_C百科 "qwertyuiopasdfghjklzxcvbnm";
$string = explode("", $string);
sort($string);
foreach ($string as $val) {
echo $val."<br>";
}
?>
I want this to output: a b c ... but how?
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>";
}
加载中,请稍侯......
精彩评论