Functions for Sorting Arrays
FUNCTION SORT BY REVERSE SORT MAINTAIN KEY/VALUE CORRELATION
sort Value No No
rsort Value Yes No
asort Value No Yes
arsort Value Yes Yes
ksort Key No Yes
krsort Key Yes Yes
usort Value User-defined No
uasort Value User-defined Yes
uksort Key User-defined Yes
<?php
$nums = array(15, 2.2, -4, 2.3, 10);
sort($nums);
printf("<pre>%s</pre>\n", var_export($nums, TRUE));
$words = array('bird', 'fish', 'George', 'Aden');
sort($words);
printf("<pre>%s</pre>\n", var_export($words, TRUE));
$dogs = array('A' => 'C', 'B' => 'D', 'X' => 'Z', 'Q' => 'T');
sort($dogs);
printf("<pre>%s</pre>\n", var_export($dogs, TRUE));
?>
Related examples in the same category