Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何对多维数组重新排序?_Php_Arrays - Fatal编程技术网

Php 如何对多维数组重新排序?

Php 如何对多维数组重新排序?,php,arrays,Php,Arrays,如何将下面的数组按字母顺序排序作为关键标准标签?我尝试使用array\u multisort、usort、rsort和sort,但都不起作用 array(3) { [0]=> array(2) { ["id"]=> string(1) "9" ["label"]=> string(26) "ffffff" } [1]=> array(2) { ["id"]=> string(2) "10"

如何将下面的数组按字母顺序排序作为关键标准
标签
?我尝试使用
array\u multisort
usort
rsort
sort
,但都不起作用

array(3) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "9"
    ["label"]=>
    string(26) "ffffff"
  }
  [1]=>
  array(2) {
    ["id"]=>
    string(2) "10"
    ["label"]=>
    string(25) "aaaaaaaaa"
  }
  [2]=>
  array(2) {
    ["id"]=>
    string(1) "6"
    ["label"]=>
    string(5) "dddddd"
  }
}

可以使用和对数组进行排序


可以使用和对数组进行排序

usort($arr, function($e1, $e2)
{
    $cmp = strcmp($e1['label'], $e2['label']);
    if($cmp == 0) { return 0; }
    return $cmp > 0 ? 1 : -1;
});