I have an array of data comprising a 'customer' and a 'Total'. (example below). It is drawn from two different databases.
I need a way to sort the array, based on the Total field, so that the Largest Total is at the top. But so far every thing I have tried has resulted in it assuming that 5 is larger than 32 [5, 32, 25, 16, 11]
What's the easiest way to achieve this? I tried adding intval() to the strcmp function, but it made no difference?
$arrayName = array();
$arrayName[] = array ('customer' => 'Customer1', 'Total' => 25);
$arrayName[] = array ('customer' => 'Customer2', 'Total' => 16);
$arrayName[] = array ('customer' => 'Customer3', 'Total' => 32);
$arrayName[] = array ('customer' => 'Customer4', 'Total' => 5);
$arrayName[] = array ('customer' => 'Customer5', 'Total' => 11);
print_r($arrayName);
print "</br>";
//Sort the Arrray by Total
function arrSort1($b, $a)
{
return strcmp($a['Total']), $b['Total']);
};
usort($arrayName, "arrSort1");
print_r($arrayName);