3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr=array( 'ACTION' => 'getsupportdepartments', 'RESULT' => 'success', 'TOTALRESULTS' => 2, 'DEPARTMENTS' => array( 'DEPARTMENT' => array( 'ID' => 2, 'NAME' => 'Sales', 'AWAITINGREPLY' => 5, 'OPENTICKETS' => 5 ), 'DEPARTMENT1' => array( 'ID' => 1, 'NAME' => 'Support', 'AWAITINGREPLY' => 15, 'OPENTICKETS' => 15))); function sortDepts(array &$arr,$sort="desc") { function asc($a,$b) { return $a["AWAITINGREPLY"]-$b["AWAITINGREPLY"]; } function desc($a,$b) { return $b["AWAITINGREPLY"]-$a["AWAITINGREPLY"]; } if($sort=="desc") usort($arr["DEPARTMENTS"],"desc"); else usort($arr["DEPARTMENTS"],"asc"); return $arr; } print_r(sortDepts($arr,"desc")); print_r(sortDepts($arr,"asc"));

preferences:
30.71 ms | 402 KiB | 5 Q