Home >Backend Development >PHP Tutorial >PHP comparison operator analysis explanation

PHP comparison operator analysis explanation

巴扎黑
巴扎黑Original
2017-08-07 10:34:071201browse

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

PHP comparison operator analysis explanation

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn