Workaround for PHP syntax 0 not equal to null empty

Source: Internet
Author: User
Today do information collection page encountered a strange problem, study for a long time to find the root cause of the problem, it is a bit strange indeed.
(the younger brother often uses the C #, Java and other languages, PHP only occasionally in use, not research very deep). Please senior PHP programmer don't laughed at

The problem is this: in PHP statements (0!=null && 0 >=0), the returned result is empty, which is really very strange.


Experiment Summary:
The PHP statements are as follows:

$index = 0;

echo "A:". $index. "
"; 0

echo "B:". ($index!=null && $index >=0). "
";//
echo "C:". (Isset ($index) && $index >=0). "
";//1

echo "D:". (0!=null). "
";//

Results:

a:0
B:
c:1
D:
Visible: The result of 0!=null is empty. To make the results correct, you can modify the $index!=null to Isset ($index)

if (Isset ($index) && $index >=0))
{
echo "contains.";
}else{
echo "does not contain.";
}


This is very strange, finally solved. Mark, please.


Address of this article:

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