PHP : natsort() function
Description
The natsort() function is used to sorts an array using a "natural order" algorithm. The function implements a sort algorithm but maintain original keys/values.
Version
(PHP 4 and above)
Syntax
natsort(array_name)
Parameter
| Name | Description | Required / Optional |
Type |
|---|---|---|---|
| array_name | The input array. | Required | Array |
Return value
TRUE on success or FALSE on failure.
Value Type : Boolean.
Pictorial Presentation :

Example :
<?php
$php_files = array("code12.php", "code22.php",
"code2.php", "code3.php", "code1.php");
natsort($php_files);
echo "List of file using natural order: ";
print_r($php_files);
?>
Output :
List of file using natural order: Array ( [4] => code1.php [2] => code2.php [3] => code3.php [0] => code12.php [1] => code22.php )
View the example in the browser
See also

