$h = 5;
$h = $h & 1; //1
$h = $h | 10;//11
$x = true and false;
var_dump($x); //true
var_dump(true and false);//false
释义:php运算符优先级 &&>=>and
$a1=null;$a2=false;$a3=0;$a4="";$a5='0';$a6='null';$a7=array();$a8=array(array());
echo empty($a1)?'true':'false';
echo empty($a2)?'true':'false';
echo empty($a3)?'true':'false';
echo empty($a4)?'true':'false';
echo empty($a5)?'true':'false';
echo empty($a6)?'true':'false';
echo empty($a7)?'true':'false';
echo empty($a8)?'true':'false';
结果:true true true true true false true false
<?php
$str1 = null;
$str2 = false;
echo $str1==$str2 ? '相等' : '不相等';
$str3 = '' ;
$str4 = 0;
echo $str3==$str4 ? '相等' : '不相等';
$str5 = 0;
$str6 = '0' ;
echo $str5===$str6 ? '相等' : '不相等';
?>
输出结果:相等 相等 不相等
释义:PHP中变量是以C语言的结构体来存储的,空字符串和NULL,false都是以值为0存储的,其中这个结构体有个Zend_uchartype;这样的成员变量,他是用来保存变量的类型的,而空字符串的类型是string,NULL的类型是NULL,false是boolean。
这一点可以用echo gettype(”);和echogettype(NULL);来打印看看!而===运算符是不单比较值,还有比较类型的,所以第三个为false。
用empty()与isset()函数判断输出下列值
$a=0;$a='0';$a='';$a=false;$a=null;
释义:isset()检测一个变量是否被设置,返回布尔值
empty()检测变量是否为空,非空或非零的值返回false
$test = 'aaaaaa';
$abc = &$test;
unset($test);
echo $abc;
$x="";
var_dump(is_null($x))
$a = "hello";
$b = &$a;
$b = "world";
echo $a;
$a=1;
$x = &$a;
$b = $a++;
echo $b;
$a=$b=$c=0;
$a = $b && $c;
echo $a.$b.$c;
$var1='abc';
$var2=&$var1;
unset($var1);
echo $var1;
echo $var2;
$var3=&$var2;
$var2=null;
echo $var2;
echo $var3;
<?php
$a=0 || $b=7 && $c=8;
echo $a,$b,$c; //118