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. The return value after comparison indicates that if str1 and str2 are equal, 0 is returned.
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 say-1, it 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 ).
The instance code is as follows:
- 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 instance code is as follows:
- 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 instance code is as follows:
- $ A = 'a ';
- $ B = 'www .phpfensi.com ';
- If ($ a = $ B)
- {
- Echo 'Equality ';
- }
- Else
- {
- Echo 'unequal ';
- }
You can also use = to compare
The instance code is as follows:
- 22 = "22"; // return true
- 22 = "22"; // Return false