Difference between 0 and null in PHP

Source: Internet
Author: User
Difference between 0 and null in PHP: Difference between 0 and null in PHP

I do not know that when you store a field with the default data of 0 in the MySQL database, an error occurs when 0 or Null is determined in the program, because 0 and Null are not completely equal, seemingly simple, but difficult to judge

The value of Null and 0 is the same, but the type is not the same. The simple point is the difference between = and =. The first = is the same as the value, but = requires the same value and the same type of value.

Null is a special type. The two types are Null, for example, the following code:

1. $ var = NULL;

2. $ var;

3.0. "0", NULL, and objects without any attributes will be considered NULL.

See the following example.

 

Running result

'Equality ''' equal ''not equal'

Therefore, values of 0 and Null are equal, but their types are not equal. Well, I made a summary of the differences between PHP 0 and null. In short, if the points are unclear, it would be okay to make a few more judgments.

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.