Home >Backend Development >PHP Tutorial >Detailed explanation of comparison operators in php_PHP tutorial
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: array with fewer members 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 will be returned.
2. Compare bool or null with other types
var_dump((bool)(null));//boolean false//convert null to false when bool;
null and other types are converted to bool and then compared, and FALSE < TRUE