I have a three dimensional array and I want to sort the arrays in the first dimension on a value in the third dimension. Like the following:
[
[
['data' => 7, 'field' => 1, 'type' => 'string'],
['data' => '2011/07/13', 'field' => -2, 'sort' => 1310594015],
['data' => 'admin', 'field' => -1, 'sort' => 'admin']
],
[
['data' => 6, 'field' => 1, 'type' => 'string'],
['data' => '2011/07/14', 'field' => -2, 'sort' => 1310667194],
['data' => 'admin', 'field' => -1, 'sort' => 'admin']
]
]
I would like to sort the arrays at the first level (i.e. there are only 2 of them) based on the value of the 'data' key, down in the third level. In this case, the two arrays at the first level should swap so the array with the value of 6 for 'data' comes before the one with 7. The array that contains the 'data' key will always be at position [0] of the second level.
usort($allArray,function($a,$b){
return $a[0]['data']-$b[0]['data'];
})