Home  >  Article  >  Backend Development  >  Equality judgment between number 0 and other variables in php

Equality judgment between number 0 and other variables in php

不言
不言Original
2018-07-05 13:48:392384browse

This article mainly introduces the equality judgment between the number 0 and other variables in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

In the practice process, It is often necessary to make `==` judgments. Sometimes 0 is used as false, but 0 and false are still different when used for comparison.

false

false= =0 is equal to true

false=='0' is equal to true

false=='' is equal to true

fasle==[] is equal to true

false=={} is equal to true

false=='123' is equal to false; 123 here can be replaced by any string except empty string and string 0

0

0==false is equal to true

0=='0' is equal to true

0=='' is equal to true

0==[] is equal to false

0=={} is equal to false

0=='123' is equal to false; here 123 can be replaced by any non-0 numeric string

0=='you Good' is equal to true; 'Hello' here can be replaced by any non-numeric string

We can draw the conclusion:

1, 0 and numeric strings or numbers when comparing numbers Whether the value is equal to 0, it is true when compared with other strings, false when compared with objects or arrays

2, false is the same as our feeling, as long as it is not empty, it is true

It should be noted that the comparison between 0 and non-numeric strings is true

The above is the entire content of this article, I hope it will be helpful to everyone's study , please pay attention to the PHP Chinese website for more related content!

Related recommendations:

The difference between static, final, interface and abstract in php

The above is the detailed content of Equality judgment between number 0 and other variables in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn