一、代码 一、代码 <?php class Test { //PHP数组按照长度降序排序 public function start() { $array = [ '你好', '你好吗', '好', 'hello', 'hi' ]; uasort($array, function ($a, $b) { return strlen($a) < strlen($b); //< 改为 > 就变成了升序排序 }); var_export($array); //打印 //array ( 1 => '你好吗', 0 => '你好', 3 => 'hello', 2 => '好', 4 => 'hi', ) } }