PHP empty function to determine 0 return TRUE or false?

Source: Internet
Author: User

In recent projects, a field is encountered that is "enabled" if the value is 0,1 when the query is not written

if isset ($args _array[' USEFLG ']) &&! Empty ($args _array[' USEFLG '])) {..... }

So I did not find the time for 0, think about it, should be 0 is considered empty. This should be the case:

if isset ($args _arrayin_array($args _arrayarray(0,1))) {... }

Read the PHP manual, Memo:

If var the value is non-null or nonzero, empty () returns FALSE . In other words,"",0,"0",,, NULL FALSE Array (),var $var; and objects that do not have any properties are considered empty, and if they are var empty, they are TRUE returned.

<? PHP $var = 0; // The result is true because the $var is empty if (empty($var)) {      echo ' $var is either 0 or not set at all ';} // The result is false because the $var has been set if (! isset ($var)) {     echo ' $var is not set at all ';}? >

The following things is considered to beEmpty: "" (AnEmpty string)0 (0 asAninteger)0.0 (0 asAfloat)"0" (0 asAstring)NULLFALSEArray() (AnEmpty Array)var $var; (a variable declared, but without a value in aclass)

Manual See: http://php.net/manual/zh/function.empty.php

PHP empty function to determine 0 return TRUE or false?

Related Article

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.