Natsort
(PHP 4, PHP 5)
Natsort-Sort arrays using the "natural sorting" Algorithm
Description
Bool natsort (array & $ array)
This function implements a sorting algorithm that is the same as the method that people usually sort character strings and maintain the association of original keys/values. This is called "natural sorting ". The difference between this algorithm and the general computer string Sorting Algorithm (used for sort () is shown in the following example.
Parameters
Array
Input array.
Return Value
Returns TRUE if the call succeeds, or FALSE if the call fails.
Example #1 natsort () examples demonstrating basic usage
<? Php
$ Array1 = $ array2 = array ("img12.png", "img10.png", "img2.png", "img1.png ");
Asort ($ array1 );
Echo "Standard sorting \ n ";
Print_r ($ array1 );
Natsort ($ array2 );
Echo "\ nNatural order sorting \ n ";
Print_r ($ array2 );
?>
The above routine will output:
Standard sorting
Array
(
[3] => img1.png
[1] => img10.png
[0] => img12.png
[2] => img2.png
)
Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)