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 );