Home Tutorial Php Phpbasics Tutorial PHP Boolean Data Types

 
 

Share on Google+Share on Google+
PHP Boolean Data Types
Posted on: March 6, 2010 at 12:00 AM
Advertisement
In this PHP tutorial we will study about boolean data type of PHP Programming Language. By default value of a boolean data type variable is false. Few interesting results are shown with the help of examples, based on explicit conversion to boolean.

PHP Boolean Data Type:

Boolean is one of the simplest data type supported by PHP. A boolean is used to express a truth value either true or false.

For conversion to boolean data type, we need to use (bool) or (boolean) casts. Though it is not necessary because whenever we need to get a boolean value from an operator, function or control structure requires a boolean value, it automatically converts.

Example of PHP Boolean Data Type :

<?php

$a=23;

var_dump ((boolean)($a));echo"<br/>";

$a=23.23;

var_dump ((boolean)($a));echo"<br/>";

$a=0.0;

var_dump ((boolean)($a));echo"<br/>";

$a=-12;

var_dump ((boolean)($a));echo"<br/>";

$a;

var_dump ((boolean)($a));echo"<br/>";

$a=NULL;

var_dump ((boolean)($a));echo"<br/>";

$a=0;

var_dump ((boolean)($a));echo"<br/>";

$a='Hello';

var_dump ((boolean)($a));echo"<br/>";

$a='a';

var_dump ((boolean)($a));echo"<br/>";

$a=(array(1,2));

var_dump ((boolean)($a));echo"<br/>";

$a=(array());

var_dump ((boolean)($a));echo"<br/>";

$a=("");

var_dump ((boolean)($a));echo"<br/>";

?>

Output:

bool(true)
bool(true)
bool(false)
bool(true)
bool(true)
bool(false)
bool(false)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)

 

Advertisement

Related Tags for PHP Boolean Data Types:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com