I have a multidimensional array that I want to sort by "price" then by "date". Here is an example of the array:
$productArray = array ( array ("Bus", "1/1/2010", 15.99),
array ("Train", "2/1/2010", 14.99),
array ("Car", "3/1/2010", 18.00),
array ("Plane", "3/1/2010", 15.99),
array ("Bike", "3/1/2010", 9.99),
array ("Truck", "1/1/2010", 19.99)
);
//sort by date
function sortElement1Asc($x, $y)
{
if ( $x[1] == $y[1] )
return 0;
else if ( $x[1] < $y[1] )
return -1;
else
return 1;
}
//sort by price
function sortElement2Asc($x, $y)
{
if ( strtotime($x[2]) == strtotime($y[2]) )
return 0;
else if ( strtotime($x[2]) < strtotime($y[2]) )
return -1;
else
return 1;
}
usort($productArray, 'sortElement1Asc');
usort($productArray, 'sortElement2Asc');
Unfortunately this is just sorting by price (or whatever i sort last).
Any ideas?