I've and array, I want to sort this array ascending order by [sys_title] key index. What should I do?
[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/
)
Expected Result should be like this:
[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/
)
You can try this piece of code:
usort($data,function($a,$b){
return strcmp($a['sys_title'],$b['sys_title']);
});
print_r($data);
Suppose your array name is $a then:
$tmp = Array();
foreach($a as &$ma) {
$tmp[] = &$ma["sys_title"];
array_multisort($tmp, $a);
}
Result will be
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/
)
)