/ Published in: PHP
For more information, see php.net, under usort
It works with dates
Replace 0 for the array's key you want to sort. For example, if you have a start_date array key you would like to compare, then you would replace 0 for start_date.
If you want to do a reverse sort, just switch the -1 and 1.
It works with dates
Replace 0 for the array's key you want to sort. For example, if you have a start_date array key you would like to compare, then you would replace 0 for start_date.
If you want to do a reverse sort, just switch the -1 and 1.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function compare ($a, $b) { //return strcmp($a["fruit"], $b["fruit"]); // in the case of the above array // note we are comparing the first element of each array if ( $a[0] < $b[0] ) { return -1; } if ( $a[0] > $b[0] ) { return 1; } // they are equal return 0; }
URL: www.coderemix.com