int strcmp (string $str1, string $str2)
Compare in binary mode
Comparison with this function is case-sensitive
Return value, if str1 If it is less than str2, it returns <0. If str1 is greater than str2, it returns >0. If they are equal, it returns 0.
<?php $str1 = "hello world"; //$str1与$str3的值相等 $str2 = "HELLO WORLD"; $str3 = "hello world"; //$str1与$str3的值相等 echo strcmp($str1,$str2); //输出1 echo strcmp($str2,$str1); //输出-1 echo strcmp($str1,$str3); //输出0?>
There is also a function strcasecmp(), the usage is similar to strcmp(), except that it is not case-sensitive, so I won’t be verbose here
The above is the detailed content of Example of string comparison function strcmp() in php. For more information, please follow other related articles on the PHP Chinese website!