php 0 = = false,0 = False will be equal, and the reason for false! = False.

Source: Internet
Author: User
First look at a special case:

Var_dump (0 = = ' false '), returns BOOL (true), PHP determines 0 equals any string;

Var_dump (0=== ' false '), which returns BOOL (FALSE), which contains both the type and the value in order to be equal.
Var_dump (0 = = false), returns BOOL (true),


Causes of the above results (translated from the official PHP document):

1, for the bool type:

When you output the bool type or use it in a statement, it is converted to a number , andtrue becomes 1and False becomes 0.

For example $a = true; Var_dump ($a + 1), return (int) 2; The $a is converted to 1, and the sum is 2;

A bool variable expresses a true value, not a 0 or a 1; A Boolean is not a symbolic constant, they are valued.

2, String type:

PHP always automatically attempts to convert a string into a digital type. such as Var_dump (' abc ' +3 '), return int (3),

First ' ABC ' is converted to the number 0, and the addition becomes 3;


Methods for detecting the type of a variable:
1, Var_dump ($param), returns the type and value of the variable.

2. Use Is_int (), Is_bool (), is_string (), function, return True and false,


Common types of conversion methods.
Variable $param

Integral type (int) $param

Character type (string) $param

Boolean type (BOOL) $param

Another way to convert to Boolean: $a =!5, $a false , $a =!! 5,$a is true;


The above describes the reason why php 0 = = false,0 = False will be equal, and false! = False. , including the aspects of the content, want to be interested in PHP tutorial friends helpful.

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