Home >>PHP Array Functions >PHP natcasesort() Function
PHP natcasesort() function is used to sort any given input array by using a "natural order" algorithm. It is case insensitive. It accepts only a single parameter $array that is the given input array. It returns a boolean value TRUE on success and FALSE on failure.
Syntax:
natcasesort($array);
Parameter | Description |
---|---|
array | This is a required parameter. It defines the array to sort. |
Here is an example of natcasesort() function in PHP:
<html> <body> <pre> <?php $x = array("a15","A10","a1","A22","a2"); natcasesort($x); echo "Natural order case insensitve: "; print_r($x); ?> </pre> </body> </html>
Example 2:
<html> <body> <pre> <?php $x = array("b15","A10","a1","B22","a2","c0","a50","A100"); natsort($x); echo "Natural order: "; print_r($x); echo "<br />"; natcasesort($x); echo "Natural order case insensitve: "; print_r($x); ?> </pre> </body> </html>