The difference between isset (variable) and direct judgment variable in PHP

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.