Php 我误解了为什么';t工作,如何修复?

Php 我误解了为什么';t工作,如何修复?,php,Php,我的练习是先将所有字符按字母顺序排列,然后是数字,最后是所有其他字符,每个字符按ASCII顺序分为以下3组。 就像 ./ssap.php toto tutu 4234 "_hop A2l+ XXX" ## "1948372 AhAhAh" AhAhAh A2l+ toto tutu XXX 1948372 4234 ## _hop 您不能使用simpleasort,请将其替换为uasort 这是一个可能方法的提示,您可以通过添加更多条件来完成此操作(请参阅内部注释): uasort(

我的练习是先将所有字符按字母顺序排列,然后是数字,最后是所有其他字符,每个字符按ASCII顺序分为以下3组。 就像

./ssap.php toto tutu 4234 "_hop A2l+ XXX" ## "1948372 AhAhAh"
AhAhAh 
A2l+
toto 
tutu
XXX 
1948372
4234 
##
_hop 

您不能使用simple
asort
,请将其替换为
uasort

这是一个可能方法的提示,您可以通过添加更多条件来完成此操作(请参阅内部注释):

uasort($ar,function($a,$b){
if(ctype_alpha(substr($a,0,1))&&is_numeric(substr($b,0,1))){
echo“比较$a$b\n”;
返回-1;
}
if(ctype_alpha(substr($b,0,1))&&is_numeric(substr($a,0,1))){
回显“比较X$a$b\n”;
返回1;
}
//在此处添加更多代码以比较单词与非字母数字字符
//以及其他自定义条件,如果您发现一些问题
回报率($a<$b)?-1:1;
});

现在到底发生了什么。现在的输出是什么,你到底想发生什么。我需要这个答案:AhAhAh A2l+toto tutu XXX 1948372 4234#####希望我的代码执行如下:4234 A2l+XXX#hop toto tutuI我们已经解决了这个问题`` ` `/usr/bin/php``但是我无法得到确切的答案。也许“##”会干扰我的代码。
#
是一个注释。这不是绳子的一部分。
uasort($ar, function($a, $b) {
    if(ctype_alpha(substr($a, 0, 1)) && is_numeric(substr($b, 0, 1))) {
        echo "comparing $a $b\n";
        return -1;
    }
    if(ctype_alpha(substr($b, 0, 1)) && is_numeric(substr($a, 0, 1))) {
        echo "comparingx $a $b\n";
        return 1;
    }

    // add more code here to compare words with non-alphanumeric characters
    // and other custom conditions if you find some issues

    return ($a < $b) ? -1 : 1;
});