<?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")
{
if($sort=="desc")
usort($arr["DEPARTMENTS"],function($a,$b){
return $b["AWAITINGREPLY"]-$a["AWAITINGREPLY"];
});
else
usort($arr["DEPARTMENTS"],function($a,$b){
return $a["AWAITINGREPLY"]-$b["AWAITINGREPLY"];
});
return $arr;
}
print_r(sortDepts($arr,"desc"));
print_r(sortDepts($arr,"asc"));
preferences:
45.6 ms | 402 KiB | 5 Q