The use of the strcmp () function is to compare two strings, and if two strings are exactly equal we return 0, otherwise there will be various return values, this function is case-sensitive and can be referenced by friends who need it.
Return value Description after comparison
Returns 0 if str1 and str2 are equal.
If the str1 is less than str2 return <0 (but not necessarily-1, many of the internet is said to be-1, is not correct, the specific value of the actual situation depends on the size).
If STR1 is greater than str2, the >0 is returned (but not necessarily 1, depending on the actual value).
Cases
The code is as follows |
Copy Code |
strcmp (Date (' y-m-d ', $user->last_time), date ("Y-m-d", Time ())) = = 0 |
If you do not distinguish between case
STRNCASECMP is used as part of a case-insensitive comparison string, starting from the beginning of the string, and the third parameter, which is the length to compare:
The code is as follows |
Copy Code |
Echo strncasecmp ("ABCDD", "ABCDE", 3); |
Returns 0, compares ABC and ABC, because it is not case sensitive, so the two are the same
PHP string Comparison We can also use = = to, as
The code is as follows |
Copy Code |
$a = ' AA '; $b = ' www.bKjia.c0m '; if ($a = = $b) { echo ' equal '; } Else { echo ' unequal '; } |
You can also use = = = to compare
The code is as follows |
Copy Code |
22 = = "22"; Returns True 22 = = = "22"; Returns false |
http://www.bkjia.com/PHPjc/628890.html www.bkjia.com true http://www.bkjia.com/PHPjc/628890.html techarticle the use of the strcmp () function is to compare two strings, if two strings are exactly equal we return 0, otherwise there will be a variety of return values, this function is case-sensitive, the need for friends to participate ...