<?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 asc($a,$b)
{
return $a["AWAITINGREPLY"]-$b["AWAITINGREPLY"];
}
function desc($a,$b)
{
return $b["AWAITINGREPLY"]-$a["AWAITINGREPLY"];
}
function sortDepts(array &$arr,$sort="desc")
{
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:
44.22 ms | 402 KiB | 5 Q