Var_dump ((bool)?) The related issues

Source: Internet
Author: User
Tags type null
Var_dump ((bool)?) The problem
Var_dump ((BOOL) ""); BOOL (FALSE)
Var_dump ((bool) 1); BOOL (TRUE)
Var_dump ((BOOL)-2); BOOL (TRUE)
Var_dump ((bool) "foo"); BOOL (TRUE)
Var_dump ((bool) 2.3e5); BOOL (TRUE)
Var_dump ((BOOL) array (12)); BOOL (TRUE)
Var_dump ((bool) array ()); BOOL (FALSE)
Var_dump ((BOOL) "false"); BOOL (TRUE)

In the past it was said that non 0 is true, but var_dump ((bool) array ()); is also false. How exactly do you judge ture or False in PHP?

------Solution--------------------
Non-0 non-NULL is True
------Solution--------------------
In PHP, when other types of variables are converted to Boolean, the following values are considered FALSE:

A Boolean value of FALSE itself;
Integer value 0 (0);
Floating-point value 0.0 (0);
An empty string (""), and a string ("0");
An array that does not include any elements;
Objects that do not include any member variables (PHP 4.0 only applies);
Special type NULL (including variables that have not yet been set);
A SimpleXML object generated from an XML document without any tags (tags);

All other values are considered TRUE (including any resources).

Note:-1 and other non-0 values (either positive or negative) are considered to be true!

Var_dump ((BOOL) ""); BOOL (FALSE)
Var_dump ((bool) 1); BOOL (TRUE)
Var_dump ((BOOL)-2); BOOL (TRUE)
Var_dump ((bool) "foo"); BOOL (TRUE)
Var_dump ((bool) 2.3e5); BOOL (TRUE)
Var_dump ((BOOL) array (12)); BOOL (TRUE)
Var_dump ((bool) array ()); BOOL (FALSE)
Var_dump ((BOOL) "false"); BOOL (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.