Sorting a multidimensional array in PHP? [duplicate]

use a compare function, in this case it compares the array’s unix timestamp value:

function compare($x, $y) {
if ( $x[4] == $y[4] )
return 0;
else if ( $x[4] < $y[4] )
return -1;
else
return 1;
}

and then call it with using the usort function like this:

usort($nameOfArray, 'compare');

This function will sort an array by its values using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.

Taken from PHP: usort manual.

Leave a Comment