PHP natsort() Function
Definition
The natsort() function sorts an array by using a "natural order" algorithm.
Syntax
PHP natsort() Function has the following syntax.
natsort(array)
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Specifies the array to sort |
Note
This function is case-sensitive.
Return
This function returns TRUE on success, or FALSE on failure.
Example 1
Sort an array:
<?php/* w w w. ja va 2 s .c o 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.