The natsort() function sorts an array by using a "natural order" algorithm.
PHP natsort() Function has the following syntax.
natsort(array)
Parameter | Is Required | Description |
---|---|---|
array | Required. | Specifies the array to sort |
This function is case-sensitive.
This function returns TRUE on success, or FALSE on failure.
Sort an array:
<?php/*from w w w. j a va 2 s . co m*/
$temp_files = array("a15","A10","A1","A22","A2");
sort($temp_files);
echo "Standard sorting: ";
print_r($temp_files);
echo "\n";
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
?>
The code above generates the following result.