Home >Backend Development >PHP Tutorial >Detailed explanation of comparison operators in php_PHP tutorial

Detailed explanation of comparison operators in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:39742browse

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824984.htmlTechArticle1. For array $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 : Has...
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