PHP natcasesort() Function
Definition
The natcasesort() function sorts an array by using a "natural order" algorithm. The values keep their original keys.
Syntax
PHP natcasesort() Function has the following syntax.
natcasesort(array)
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Array to sort |
Return
This function returns TRUE on success, or FALSE on failure.
Note
This function is case-insensitive.
Example 1
Sorts an array by using a "natural order" algorithm.
<?php/*w w w .jav a2s .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.