我和数组,我想按 [sys_title] 键索引升序排序该数组。我该怎么办?
[0] => Array
(
[sys_id] => 9
[sys_title] => Checklist
[sys_home] => /cp/system/chl/
)
[1] => Array
(
[sys_id] => 8
[sys_title] => Bakery Ordering System
[sys_home] => /cp/system/bos/
)
预期结果应该是这样的:
[0] => Array
(
[sys_id] => 8
[sys_title] => Bakery Ordering System
[sys_home] => /cp/system/bos/
)
[1] => Array
(
[sys_id] => 9
[sys_title] => Checklist
[sys_home] => /cp/system/chl/
)
你可以试试这段代码:
usort($data,function($a,$b){
return strcmp($a['sys_title'],$b['sys_title']);
});
print_r($data);
假设你的数组名称是 $a 那么:
$tmp = Array();
foreach($a as &$ma) {
$tmp[] = &$ma["sys_title"];
array_multisort($tmp, $a);
}
结果将会是
Array
(
[0] => Array
(
[sys_id] => 8
[sys_title] => Bakery Ordering System
[sys_home] => /cp/system/bos/
)
[1] => Array
(
[sys_id] => 9
[sys_title] => Checklist
[sys_home] => /cp/system/chl/
)
)