Home >>PHP String Functions >PHP strnatcasecmp() Function
PHP strnatcasecmp() function is used to compare two given strings using the "natural order" algorithm. It accepts two strings as input parameter and returns an integer value as output. It is similar to strnatcmp() but the only difference is strnatcasecmp() function is case-insensitive.
Syntax:
strnatcasecmp( $string1, $string2);
Parameter | Description |
---|---|
string1 | This is a required parameter. This parameter defines the first string to compare. |
string2 | This is a required parameter. This parameter defines the second string to compare. |
Here is an example of strnatcasecmp() function in PHP:
<html> <body> <?php echo strnatcasecmp("PHPTPOINT","php"); echo "<br>"; echo strnatcasecmp("PhpPOint","PHPTPOINT"); echo "<br>"; echo strnatcasecmp("PhpTpoint","PHPTPOINT"); ?> </body> </html>
Here is an another example of strnatcasecmp() function in PHP:
<html> <body> <pre> <?php $arr1 = $arr2 = array("1","2","10","001","1000","20","130","200"); echo "Standard string comparison"."<br>"; usort($arr1,"strcmp"); print_r($arr1); echo "<br>"; echo "<br>"; echo "Natural order string comparison"."<br>"; usort($arr2,"strnatcmp"); print_r($arr2); ?> </pre> </body> </html>