If you compare an integer and a string, the string will be converted to an integer. If comparing two numeric strings, compare as integers. This rule also applies to switch statements
1, for arrays
$a=array(1,2,3,6);
$b=array(1,2,3,6,8);
echo "\n";
var_dump( $a>$b);
var_dump( $a==$b );
var_dump( $a<$b);
Result:
boolean false
boolean false
boolean true
ps: with fewer members The array is smaller
$a=array(1,2,3,6,9);
$b=array(1,2,3,6,8);
echo "\ n";
var_dump( $a>$b);
var_dump( $a==$b);
var_dump( $a<$b);
boolean true
boolean false
boolean false
ps: Compare values one by one
$a=array(1,2,3,6,'b'=>3);
$b=array(1,2,3,6,8);
echo "\n";
var_dump( $a>$b);
var_dump( $a==$ b);
var_dump( $a<$b);
boolean false
boolean false
boolean false
ps: If the key in operand 1 does not exist In operand 2, the arrays cannot be compared, and false is returned.
2. Compare bool or null with other types
var_dump((bool)(null));//boolean false//null is converted to false when bool;
null and other types are converted to bool and then compared, and FALSE < TRUE
The above is the detailed content of PHP comparison operator analysis explanation. For more information, please follow other related articles on the PHP Chinese website!