PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




Boolean data type in PHP


Tutorials »Php »

Topic

How to define a boolean variable and assign value?



Explanation

A boolean type is typically denoted by "bool" or "boolean".It can hold values either "true" (1) or "false" (0). Any non zero values and non empty string are also considered as TRUE.

When you want to declaring boolean variable, you can declare as given below

boolean $variable;

where boolean denotes the type of the variable.

You can also declare variable without datatype, in such case PHP will try to determine type of variable based on the value hold by that variable. For example if you assign a string value to variable, this variable becomes a string variable. Below I have declared a variable without its type.

$variable= true;

Here $variable is a variable of type boolean.

If you want to get a type of a variable, you can use gettype() function.
Example:

$variable=true;
print gettype($variable);


Above code will print type as boolean.





Other Links

web hosting