I have a multi dimensional array which has gone out of whack and I need to sort it, but am having trouble.
I have an array $dateOrders as such:
Array
(
[21/11/2005] => Array
(
[orders] => Array
(
[1013] => Array
(
[uts] => 1132584078
[products] => Array
(
[RW24] => Array
(
[prodQty] => 1
)
)
[salePrice] => 30.75
[costPrice] => 18.19
)
[1014] => Array
(
[uts] => 1132584250
[products] => Array
(
[DB24] => Array
(
[prodQty] => 1
)
)
[salePrice] => 41.73
[costPrice] => 23.9
)
[1003] => Array
(
[uts] => 1132582405
[products] => Array
(
[DB2] => Array
(
[prodQty] => 1
)
)
[salePrice] => 27.78
[costPrice] => 17.91
)
)
[saleTotal] => 100.26
[costTotal] => 60
[orderTotal] => 3
)
)
Within each date key in $dateOrders, I would like to sort by $dateOrders[$date]['orders'][$orderID]['uts'] if poss, or $dateOrders[$date]['orders'][$orderID] if its easier.
I've tried using array_multisort which has always worked for these kind of things in the past, by doing this
foreach($dateOrders as $date=>$dateinfo)
{
foreach($dateinfo['orders'] as $orderID=>$orderInfo)
{
$timeOrder[$orderID] = $orderInfo['uts'];
}
array_multisort($timeOrder, SORT_ASC, $dateOrders[$date]['orders']);
}
But this removes the associative keys and outputs an array like:
Array
(
[21/11/2005] => Array
(
[orders] => Array
(
[0] => Array
(
[uts] => 1132582405
[products] => Array
(
[DB2] => Array
(
[prodQty] => 1
)
)
[salePrice] => 27.78
[costPrice] => 17.91
)
[1] => Array
(
[uts] => 1132584078
[products] => Array
(
[RW24] => Array
(
[prodQty] => 1
)
)
[salePrice] => 30.75
[costPrice] => 18.19
)
...and so on
So its removed the keys from the orders array. I think array_multisort is supposed to do this, but i've tried sort, asort, ksort and they seem to have no effect.
What am I doing wrong?