Use "= =" to judge, as for it and "= =" The difference, simple is the former emphasis on "identical (same, exactly the same)" type also requires the same, the latter requires "equal (equal)", the value is the same. Or use strcmp to judge, but this will tell you whether two strings are equal, but can't tell you where they are different.
Generally can use!=, = = Compare two objects are equal, the reason is said to be two objects, because they are not necessarily all strings, can also be integral type and so on. like
Copy Code code as follows:
$a = "Joe";
$b = "Jerry";
if ($a!= $b)
{
echo "Not Equal";
}
Else
{
echo "equal";
}
If you compare with!==, = = = Two objects must be of equal type to return True, otherwise the string will be automatically converted to the appropriate type for comparison by ==,!=.
Copy Code code as follows:
22 = = "22"; Returns True
22 = = "22"; Returns the functions that falsephp uses for string comparisons: strcmp (), strcasecmp (), strncasecmp (), strncmp (), they are all integers larger than 0 if the former is larger than the latter, and returns an integer less than 0 if the former is smaller ; If the two are equal, return 0.
1)STRCMP is a string comparison for case sensitivity (i.e., case sensitive):
2)Echo strcmp ("ABCDD", "ABCDE"); Returns 1 (>0), comparing "B" and "B".
3)STRCASECMP for case-insensitive string comparisons:
4)Echo strcasecmp ("ABCDD", "ABCDE"); Returns-1 (<0), comparing "D" and "E"
STRNCMP is used to compare a portion of a string, starting at the beginning of the string, and the third parameter, the length to compare:
echo strncmp ("ABCDD", "ABCDE", 3); Returns 1 (>0), comparing ABC and ABC
STRNCASECMP is used as part of a case-insensitive comparison string, starting at the beginning of the string, the third parameter, the length to compare:
Echo strncasecmp ("ABCDD", "ABCDE", 3); Returns 0, comparing ABC and ABC, because they are not case-sensitive, so they are the same.
More of a situation is to compare the size of the string alone, can not reach our predetermined requirements, such as the normal 10.gif will be larger than 5.gif, but if the application of the above several functions, will return 1, that is, 10.gif than 5.gif, in this case, PHP provides two natural-contrast functions strnatcmp,strnatcasecmp:
Echo strnatcmp ("10.gif", "5.gif"); Return 1 (>0)
Echo strnatcasecmp ("10.gif", "5.gif"); Return 1 (>0)