WHAT IS THE SYNTAX OF THE STRCASECMP() FUNCTION IN PHP?
strcasecmp(string1,string2)
Parameter | Description |
---|---|
string1 | Required. Specifies the first string to compare |
string2 | Required. Specifies the second string to compare |
EXAMPLES OF THE STRCASECMP() FUNCTION
Example 1. In this example, we compare two strings (case-insensitive).
<?php
echo strcasecmp("Hello world!","HELLO WORLD!");
?>
Example 2. In this example, we compare two strings (case-insensitive = HELLO and hELLo will output the same).
<?php
echo strcasecmp("Hello","HELLO");
echo "<br>";
echo strcasecmp("Hello","hELLo");
?>
Example 3. In this example, we different return values.
<?php
echo strcasecmp("Hello world!","HELLO WORLD!"); // The two strings are equal
echo strcasecmp("Hello world!","HELLO"); // String1 is greater than string2
echo strcasecmp("Hello world!","HELLO WORLD! HELLO!"); // String1 is less than string2
?>