Home >Backend Development >PHP Tutorial >php中的比较运算符详解_php实例

php中的比较运算符详解_php实例

WBOY
WBOYOriginal
2016-06-07 17:23:33973browse

php中的比较运算符详解_php实例

1、对于数组
$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

结果:
boolean false
boolean false
boolean true

ps:具有较少成员的数组较小

$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( $aboolean true
boolean false
boolean false

ps:  挨个值比较
 
$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( $aboolean false
boolean false
boolean false

ps: 如果运算数 1 中的键不存在于运算数 2 中则数组无法比较,都返回false。

2、对于bool或者null和其他类型比较
 
var_dump((bool)(null));//boolean false//null转换为bool时为false;

null和其他类型转换为bool,然后再比较,而且FALSE

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