The strcmp () function is used to compare two strings. If the two strings are completely equal, 0 is returned. Otherwise, various return values are returned. This function is case-sensitive and can be used as a reference.
Return Value After comparison
If str1 and str2 are equal, 0 is returned.
If str1 is smaller than str2, return <0 (but not necessarily scheduled-1, many online saying-1, is incorrect, the specific value size depends on the actual situation ).
If str1 is greater than str2, return> 0 (but different timing 1, the specific value size depends on the actual situation ).
Example
| The Code is as follows: |
Copy code |
Strcmp (date ('Y-m-d', $ user-> last_time), date ("Y-m-d", time () = 0 |
If case insensitive
Strncasecmp is used to compare a part of a case-insensitive string. It starts from the beginning of the string and the third parameter is the length to be compared:
| The Code is as follows: |
Copy code |
Echo strncasecmp ("abcdd", "abcde", 3 ); |
// Return 0, which compares abc and abc. The two are the same because they are case insensitive.
We can also use = to compare php Strings, as shown in
| The Code is as follows: |
Copy code |
$ A = 'a '; $ B = 'www. bKjia. c0m '; If ($ a = $ B) { Echo 'Equality '; } Else { Echo 'unequal '; } |
You can also use = to compare
| The Code is as follows: |
Copy code |
22 = "22"; // return true 22 = "22"; // return false |