The difference between isset (variable) and direct judgment variables in PHP
When the variable is an empty string and a Boolean value of false and the value 0 o'clock, isset all returns True, directly judging all return false:
$empty='';echo (isset($empty)?'1':0);//1echo'
';echo ($empty?'1':0);//0
$empty = False ; echo (isset ( $empty )? ' 1 ' : 0 ); //1 echo " ; echo ( $empty ? ' 1 ' : 0 ); //0
$empty=0;echo (isset($empty)?'1':0);//1echo'
';echo ($empty?'1':0);//0
They are indistinguishable only when the variables are null:
$empty=null;echo (isset($empty)?'1':0);//0echo'
';echo ($empty?'1':0);//0
Although Isset does not work in judging variables, it is useful to have a variable in the judgment array:
$arr = Array ( ' 1 ' =>1 , ' 3 ' =>3 ); $temp =null ; //ps:php array is different from map, if there is no key and you go to the value will raise an error instead of returning null, so to have a corresponding judgment, first judge the value of if (isset ( $arr [ ' 2 ' ]) {//effect is equivalent to Array_key_exists (' 2 ', $arr), but the relative code is a little shorter $temp = $arr [ ' 2 ' ];} echo $temp ;
And the isset do not know can go to the official website to see the understanding:
http://php.net/manual/zh/function.isset.php
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.