Syntax:strnatcasecmp ($string1, $string2)
Parameters:the function takes two required string parameters, as shown in the above syntax. These parameters are defined below:
- $string1:This parameter specifies the first string to compare.
- $string2:this parameter specifies the second row to compare.
Return Values:This function returns a positive integer, negative integer, or 0 based on the following conditions:
- Returns 0,if the two strings are equal
- Returns positive (> 0),if $string1 is greater than $string2.
- Returns a negative value (< 0),if $string1 is less than $string2.
Examples:
Input: $string = "Geek", $string2 = "GEEK" Output: 0 Input: $string = "Geeks", $string2 = "Geek" Output: 1
The programs below illustrate the function strnatcasecmp ( ):
Program 1:This program illustrates a simple use of the strnatcasecmp() function.
Php
echo
strnatcasecmp
(
"Geeks"
,
"Geek "
);
?>
Exit1
Program 2:This program illustrates the case insensitivity of the strnatcasecmp() function.
php
// case sensitive function strnatcasecmp()
echo
strnatcasecmp
(
"Geeks"
,
"GEEKS"
);
echo
""
;
// Case-sensitive strnatcmp() function
echo
strnatcmp
(
" Geeks "
,
" GEEKS "
);
?>
Exit0 1
PHP Strnatcasecmp () Function cmp: Questions
PHP Strnatcasecmp () Function PHP: Questions