Introduction
I am describing two string functions in PHP; the functions are "strcmp()" which is case sensitive and "strcasecmp()" which is case insensitive. I first discuss the strcmp function with syntax and an example. The strcmp() function is a string function to compare two strings passed as parameters.
Syntax
|
strcmp($string1, $string2); |
strcmp() returns:
-
< 0 if string1 is less than string2.
-
> 0 if string1 is greater than string2.
-
0 if str1 and str2 are equal.
Example1
The strcmp() function returns a positive value when the first parameter is greater than the second parameter, so the output is a positive value. Such as:
<?php
$string1 = 'MCN';
$string2 = 'ABC';
$result = strcmp($string1,$string2);
echo "Print the result <b>$result</b>";
?>
Output

Example2
The Strcmp() function returns a negative value, when the first parameter is less than the second parameter, so the output is a negative value. Such as:
<?php
$string1 = 'ABC';
$string2 = 'MCN';
$result = strcmp($string1,$string2);




Join the conversation! Your thoughts help the community grow.