I have a multidimensional array.
$array[0] = array(1, 8, 2);
$array[1] = array(5, 6, 15);
$array[2] = array(-8, 2, 1025);
I am wondering what the most efficient way to order the parent array by a particular property of it’s sub array. For example, I want to put them in ascending order of $sub_array[1], so the parent array would be ordered 2,1,0.
sortand its cousins have variations where you can supply your own sorting callback function:usort,uasort(which maintains indexes), anduksort(which sorts on the keys. You’ll have to create your own sorting callback to do what you want to do here.Note that my function will sort two subarrays as being equal if $subarray[1] is equal, so if you want to be more specific, you can add more rules for when
$a[1] == $b[1].