Home >Backend Development >PHP Tutorial >Example of string comparison function strcmp() in php
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 cc4d5e344e7010ceeee94a4ed9c60bdb0. 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 go into details 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!