Php syntax 0 is not equal to null.

Source: Internet
Author: User
In php syntax, 0 is not equal to null. the solution encountered a strange problem during the information collection page today. after studying for a long time, I found the root cause of the problem, which is indeed a bit strange.
(The younger brother often uses C #, java, and other languages. php is only used occasionally, but not deeply researched ). Don't laugh at senior php programmers

The problem is: in the php statement (0! = Null & 0> = 0), the returned result is null, which is really strange.


Experiment summary:
The php statement is 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 )."
";//

Result:

A: 0
B:
C: 1
D:
Visible: 0! = Null: The result is null. to make the result correct, you can change it to $ index! = Null to isset ($ index)

If (isset ($ index) & $ index> = 0 ))
{
Echo "include .";
} Else {
Echo "does not contain .";
}


This is very strange and finally solved. Mark.


Address:

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.