【发布时间】:2021-02-26 14:54:58
【问题描述】:
我正在尝试对数组进行排序,比如说:
['qwe',12,'*', 324, '$we'],但我希望它排序:首先是数字,然后是特殊字符和字母。
我知道我必须使用usort(),但不知道如何编写回调函数来实现我需要的。
有什么想法吗?
【问题讨论】:
-
特别注意手册中的这句话:
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.因此,您的回调必须说所有数字都小于特殊字符并且小于字母。 -
任务描述不充分。例如,像“abc1”这样的字符串是如何分类的?分类适用于字符串中的每个字符?