Monday, 29 September 2014

strnatcmp in PHP

 PHP strnatcmp() 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:

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

string2 : Required. Specifies the second string

Tip: This function is case-sensitive.

Example:

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

0 comments:

Post a Comment