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

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 '), returns BOOL (false), and the congruent contains type and value to be equal.
Var_dump (0 = false), returning bool (true),

Reasons for the above results (translated from the official PHP document): 1. For bool: When you output a bool or use it in a statement , it is converted to a number, true to 1 , and false to 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 an expression of 0 or 1; A Boolean is not a symbolic constant.
2, String: PHP will always automatically try to convert the string into a numeric type. For example Var_dump (' abc ' +3 '), returns INT (3) , first ' abc ' is converted to the number 0, the addition becomes 3;
Methods for detecting the types of variables:
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,
A common type conversion method.
Variable $param integral (int) $param character type (String) $param Boolean (bool) $param another way to convert to a Boolean: $a =!5, $a to false, $a =!! 5, $a is true;



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.