• Tutorial List

When PHP Converts a value to a Boolean value

Last updated Jul 08, 2020
When PHP Converts a value to a Boolean value

Sometimes in PHP, a value will be automatically converted to boolean if an operator, function or control structure requires a boolean argument.

When converting to boolean, All the values are considered TRUE except the following values. The following values are considered FALSE.

  • The boolean FALSE itself
  • 0 Integer (Zero)
  • 0.0 float
  • Empty String '' & the string '0'
  • Empty array
  • NULL value
  • SimpleXML objects created from empty tags
<?php
if(FALSE || 0 || 0.0 || '' || '0' || [] || NULL){
    echo "These are all TRUE values";
}
else{
    echo "These are all FALSE values";
}

?>
Browser Output
These are all FALSE values

Ask Questions

Your email address will not be published. Required fields are marked *