开发者

Sorting a array in alphabetical order in php?

开发者 https://www.devze.com 2023-03-21 06:24 出处:网络
<?php $string =开发者_C百科 \"qwertyuiopasdfghjklzxcvbnm\"; $string = explode(\"\", $string); sort($string);
<?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>";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消