Monday 29 September 2014

strnatcasecmp in PHP

 PHP strnatcasecmp() function is utilized to analyze two strings using a "natural" algorithm.
The function returns :

0 –if the two strings are exactly equivalent.
<0 –if smaller byte is found in the string1.
>0 –if smaller byte is found in the string2.
Syntax:

strnatcasecmp(string1,string2)
string1 : Required. Specifies the first string

string2 : Required. Specifies the second string

Tip: This function is case-insensitive.

Example:

<?php
echo strnatcasecmp("4Good Morning","12Good Morning");
echo "<br />";
echo strnatcasecmp("12Good Morning","4Good Morning");
?>
Output will be:
-1
1

0 comments:

Post a Comment