boolean: Converting to boolean
Converting to boolean
To explicitly convert a value to boolean, use the (bool) or (boolean) casts.
In most cases the cast is unnecessary, since a value will be automatically converted if an operator, function or control structure requires a boolean argument.
Considered FALSE
<?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)
?> - The boolean FALSE itself.
- The integer 0 (zero).
- The float 0.0 (zero).
- The empty string, and the string &quot;0&quot;.
- An array with zero elements.
- The special type NULL (including unset variables).
- SimpleXML objects created from empty tags.
Semantic portal