I tried implementing a solution for my 3-level multi-dimensional array. The problem arose when I realised I can't use keynames to target a value as they're dynamically created (SKU-style).
A skimmed version of my array data:
Array
(
['weeks'] => Array
(
[14] => Array
(
[some_sku] => 28.5
[some_sku_1] => 10.8
[some_sku_2] => 11.21
[some_sku_3] => 19.98
[some_sku_4] => 20.79
)
[31] => Array
(
[some_sku_1] => 28.5
[some_sku_5] => 10.8
[some_sku_6] => 11.21
[some_sku_7] => 19.98
[some_sku_9] => 20.79
)
)
)
I thought maybe I could sort the individual arrays within the "mothership" array but that doesn't seem to achieve what I want:
foreach ($data as $item)
{
foreach ($item as $el)
{
usort($el, function($a, $b){return $a > $b;});
}
}
But the data remains the same: https://3v4l.org/E6W8Z
My guess is that whilst it may happen it doesn't store the values in the array. I also can't assign the output of usort()
as that returns a boolean instead of the sorted array.
How am I able to sort my child arrays within the parent array by value (high - low)?