Boolean (Boolean) type in PHP _php example

Source: Internet
Author: User

When converted to Boolean, the following values are considered FALSE:

The Boolean value FALSE itself

The value of the integer 0 (0)

The floating-point value of 0.0 (0)

empty string, and 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 (includes variables that have not yet been set)

SimpleXML object generated from an XML document that does not have any tags (tags)

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

Warning
-1 and other non-0 values (whether positive or negative) are considered to be true!

Copy Code code as follows:

<?php
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)



Boolean spin string when,true=&gt;1,false=&gt; "";

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.