排序方法:
array_multisort(array_column($array,'sort'),SORT_ASC,$array);
实际应用:
<?php
$array=[
["name"=> "事例5",
"sort"=> 5],
["name"=> "事例2",
"sort"=> 2],
["name"=> "事例4",
"sort"=> 4],
["name"=> "事例3",
"sort"=> 3]
];
array_multisort(array_column($array,'sort'),SORT_ASC,$array);
print_r($array);
打印输出结果:
Array ( [0] => Array ( [name] => 事例2 [sort] => 2 ) [1] => Array ( [name] => 事例3 [sort] => 3 ) [2] => Array ( [name] => 事例4 [sort] => 4 ) [3] => Array ( [name] => 事例5 [sort] => 5 ) )
版权声明:本文为qq_24468953原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。