The natcasesort() function sorts an array by using a "natural order" algorithm. The values keep their original keys.
PHP natcasesort() Function has the following syntax.
natcasesort(array)
Parameter | Is Required | Description |
---|---|---|
array | Required. | Array to sort |
This function returns TRUE on success, or FALSE on failure.
This function is case-insensitive.
Sorts an array by using a "natural order" algorithm.
<?php//w w w. jav a 2s. c o m
$temp_files = array("A1","A11","A12","B","B0","java2s.com");
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
echo "<br />";
natcasesort($temp_files);
echo "Natural order case insensitve: ";
print_r($temp_files);
?>
The code above generates the following result.