A basic question. thank you.

Source: Internet
Author: User
A basic question. thank you. EchoNULL = false? & Quot; true & quot;: & quot; false & quot; // output trueechofalse = '0 '? & Quot; true & quot;: & quot; false & quot; a basic question. thank you.
Echo NULL = false? "True": "false"; // outputs true
Echo false = '0 '? "True": "false"; // outputs true

Why is false output below?
Echo NULL = '0 '? "True": "false"; // outputs false


In PHP, variables are stored in a C-language structure. empty strings, NULL strings, and false are both stored with a value of 0.
The above sentence is correct.

------ Solution --------------------
Php is a weak language.
So when you change
Echo false = 0? "True": "false"; // outputs true

It is also true, so you can't simply judge '0' to say that it is a string type, because you use =
It does not compare the types

If you want to judge whether the string 0 is
Echo false = '0 '? "True": "false"; // outputs false

Discussion

Is false a string?
Why echo false = '0 '? "True": "false"; // outputs true

Reference:

'0' is a string. if it is null = "", it will be true.

------ Solution --------------------
Come and read the manual with me ....
Http://ca.php.net/manual/en/language.operators.comparison.php
Intermediate Comparison with Various Types table ....

For comparison of different types of variables, type conversion is required first, and how conversion determines the final result ....


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.