Other types in PHP are converted to the Bool type.

Source: Internet
Author: User
This article summarizes some situations when PHP is transitioned to Boolean (bool). It is very simple. if you need it, you can refer to the following questions: in PHP, if (true = 2) will return true or false?

The result is true. in this case, I will test other php Data types.

Conclusion:

When converted to the bool type, the following data types are converted to false:

1. integer 0

2. empty string

3. empty array

4. NULL

Please add...

Test code:

<? Phpfunction p ($ title, $ mybool) {echo"
". $ Title; echo var_dump ($ mybool )."
";} Class foo {function do_foo () {echo" Hello! ";}} Echo"
Convert other types in PHP to Bool type
"; // Zero $ n0 = boolval (0); p (" zero: ", $ n0); // positive integer $ n = boolval (2); p (" positive integer: ", $ n); // negative integer $ nx = boolval (-2); p (" negative integer: ", $ nx ); // character space $ ss = boolval (""); p ("character space:", $ ss); // empty string $ sn = boolval (""); p ("null string:", $ sn); // String $ s = boolval ("chinacion"); p ("string:", $ s ); // empty array $ an = boolval (array (); p ("empty array:", $ ); // array $ a = boolval (array (0 => 1); p ("array:", $ a); // null type $ nu = boolval (NULL ); p ("NULL:", $ nu); // object $ bar = new foo; $ bar; $ obj = boolval ($ bar); p ("Object :", $ obj );

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.