what is the syntax of the STRNATCASECMP() function in php?
strnatcasecmp(string1,string2)
Parameter | Description |
---|---|
string1 | Required. Specifies the first string to compare |
string2 | Required. Specifies the second string to compare |
examples of the STRNATCASECMP() function
Example 1. In this example, we compare two strings using a “natural” algorithm (case-insensitive).
<?php
echo strnatcasecmp("2Hello world!","10Hello WORLD!");
echo "<br>";
echo strnatcasecmp("10Hello world!","2Hello WORLD!");
?>
Example 1. In this example, we find difference between natural algorithm (strnatcmp) and regular computer string sorting algorithms (strcmp).
<?php
$arr1 = $arr2 = array("pic1","pic2","pic10","pic01","pic100","pic20","pic30","pic200");
echo "Standard string comparison"."<br>";
usort($arr1,"strcmp");
print_r($arr1);
echo "<br>";
echo "Natural order string comparison"."<br>";
usort($arr2,"strnatcmp");
print_r($arr2);
?>