This article mainly introduces the comparison of PHP strings, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
int strcmp( string $str1 , string $str2 )
Pay attention to the comparisonDifferentiate sizeWrite.
Parameters
str1The first string.
str2The second string.
Return value
If str1 is less than str2, return a negative number; if str1 is greater than str2 , returns a positive number; if they are equal, 0 is returned. (Returns 0 if equal)
Example:
<?php $var1="Hello"; $var2="Hello"; if(strcmp($var1,$var2)==0) {echo'相等'; } else { echo'不相等'; } ?>
strcasecmp —Binary safe comparison of strings (case insensitive)
int strcasecmp(string$str1,string$str2)
Return value: If str1 is less than str2, return < 0; if str1 is greater than str2, return > 0; if they are equal, return 0. str1
The first string.
str2
The second string.
Example:
<?php $var1="Hello"; $var2="hello"; if(strcasecmp($var1,$var2)==0){ echo'$var1isequalto$var2inacase-insensitivestringcomparison'; } ?>
The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Instances of php implementing PageRank
The above is the detailed content of About comparison content of php strings. For more information, please follow other related articles on the PHP Chinese website!