PHP strcasecmp Function

What is strcasecmp Function and how it is used in string?


In PHP, strcasecmp function is used to compare two strings and is case-insensitive.



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 :

echo strcasecmp("Hi folks!","HI FOLKS!");
echo "<br>";
echo strcasecmp("Hi folks!","HI!");
echo "<br>";
echo strcasecmp("Hi!","HI FOLKS!");
echo "<br>";
Result :


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".

PHP Topics

Ask Questions

Ask Question