The difference between isset variable and direct judgment variable in PHP

Source: Internet
Author: User
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);//1echo'
';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中数组不同于map,如果没有key而你去取值会引发错误而不是返回null,所以要有对应的判断,先判断再取值if (isset($arr['2'])) {//效果等同于array_key_exists('2', $arr),但相对代码短一点$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.

The above describes the PHP isset variable and the difference between the direct judgment variable, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.