Use of PHP string-based comparison functions strcmp () and strcasecmp. The difference between "" and "" is simply that the former emphasizes that the "identical (same, identical)" type also requires the same; the latter requires "equal (equal to" = "for judgment. The difference between" = "and" = "is simply that the former emphasizes" identical (identical, identical) "type also requires the same; the latter requires" equal (equal) ", the value is the same. Or use strcmp to determine, but this can tell you whether the two strings are equal, but it cannot tell you where the difference is.
Generally used! =, = Compares whether two objects are equal. The reason is that they are two objects, because they are not all strings and can also be integers.
For example
The code is as follows:
$ A = "joe ";
$ B = "jerry ";
If ($! = $ B)
{
Echo "not equal ";
}
Else
{
Echo "equal ";
}
If yes! =, = For comparison, if the two objects must be of the same type, true is returned; otherwise, = ,! = The string is automatically converted to the corresponding type for comparison.
The code is as follows:
22 = "22"; // return true
22 = "22"; // returns the functions used by falsePHP for string comparison: strcmp (), strcasecmp (), strncasecmp (), strncmp (), if the former is greater than the latter, an integer greater than 0 is returned. if the former is smaller than the latter, an integer smaller than 0 is returned. if the two are equal, 0 is returned.
1)Strcmp is a case-sensitive string comparison:
2)Echo strcmp ("abcdd", "abcde"); // returns 1 (> 0), comparing "B" and "B"
3)Strcasecmp is used for case-insensitive string comparison:
4)Echo strcasecmp ("abcdd", "abcde"); // returns-1 (<0), comparing "d" and "e"
Strncmp is used to compare a part of a string, starting from the beginning of the string, and the third parameter, which is the length to be compared:
Echo strncmp ("abcdd", "abcde", 3); // returns 1 (> 0), comparing abc and abc
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:
Echo strncasecmp ("abcdd", "abcde", 3); // returns 0, comparing abc and abc. The two are the same because they are case insensitive.
Another scenario is to compare the size of a string to meet our predefined requirements. for example, 10.gif is larger than 5.gif as usual, but if the above functions are applied,-1 is returned, in this case, php provides two natural comparison functions, strnatcmp and strnatcasecmp:
Echo strnatcmp ("10.gif"," 5.gif"); // return 1 (> 0)
Echo strnatcasecmp ("10.gif"," 5.gif"); // return 1 (> 0)
The sequence (same, identical) type also requires the same; the latter requires "equal (equal...