PHP strnatcasecmp() Function

PHP strlen() Function
PHP strnatcmp() Function

what is the syntax of the STRNATCASECMP() function in php?

strnatcasecmp(string1,string2)
ParameterDescription
string1Required. Specifies the first string to compare
string2Required. Specifies the second string to compare
PHP STRNATCASECMP() method

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);
?>
PHP strlen() Function
PHP strnatcmp() Function
en English
X
Scroll to Top