PHP comparison operator analysis explanation

巴扎黑
Release: 2023-03-14 18:24:02
Original
1097 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!