"Natural" sorting of PHP arrays. Natsort (PHP4, PHP5) natsort uses a natural sorting algorithm to sort arrays. boolnatsort (array $ array) this function provides a natsort that is generally used to sort alphanumeric strings.
(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
$ 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
)
Http://www.bkjia.com/PHPjc/477517.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477517.htmlTechArticlenatsort (PHP 4, PHP 5) natsort use natural sorting algorithms to sort arrays bool natsort (array $ array) this function is used to sort letters, numbers, and strings...