I have a big array with child array with child arrays on it.
The scheme is like this:
$bigArray['apple'][] = array('shop1', 'Fruit', '7');
$bigArray['apple'][] = array('shop2', 'Fruit', '5');
$bigArray['pear'][] = array('shop2', 'Fruit', '3.5');
$bigArray['banana'][] = array('shop1', 'Fruit', '2');
So in this case
$bigArray['apple']
contains 2 arrays.
First thing is, I want to sort this arrays from the 3rd parameter(price) in ascending order (lowest price to highest price) So when printed it will display:
'shop2', 'Fruit', '5' ->lowest price
'shop1', 'Fruit', '7'
Second thing is, I want to sort the entire array $bigArray
in ascending order
(lowest price to highest price again); Now since arrays like $bigArray['apple']
are already sorted, in the $bigArray
sort only $bigArray['apple'][0]
first array
will be taken into consideration because [0] will be the lowest price of this
child array, already sorted.
So in the end when printed $bigArray
will display:
'shop1', 'Fruit', '2'
'shop2', 'Fruit', '3.5'
'shop2', 'Fruit', '5'
....
I have been struggling with usort but is far more complicated for me to work with multidimensional associative arrays.
Thank you.