PHP strcasecmp Function
What is strcasecmp Function and how it is used in string?
Explanation
In PHP, strcasecmp function is used to compare two strings and is case-insensitive.
Syntax:
strcasecmp(string1,string2)
In the above syntax "string1", "string2" specifies the strings to be compared, the function returns "0" if both strings are equal, returns a value ">0" if "string1" is greater than "string2", returns "<0" if "string1" is less than "string2".
Example :
<?php
echo strcasecmp("Hi folks!","HI FOLKS!");
echo "<br>";
echo strcasecmp("Hi folks!","HI!");
echo "<br>";
echo strcasecmp("Hi!","HI FOLKS!");
echo "<br>";
?>
Result :
0
-1
1
In the above example,at first both the string are equal so it returns "0", secondly "string1" is greater than "string2" so it returns "-1",thirdly "string1" is lesser than "string2" so it returns "1".