Data Types in PHP:
PHP data type mainly divided into three types:
Scalar Data Type
Compound Data Type
Special Data Type
Scalar Data Type:
Scalar data type is divided into four different types. All primitive types come under scalar data type.
Boolean Data Type:
This data type represents either true or false. In PHP value of true is one and false doesn’t contain any value.
is_bool() Function:
By using this function we can check whether the input variable is Boolean or not.
(bool)variable Function:
By using this function we can convert input data type into a Boolean data type.
Integer Data Type:
This data type can hold numeric values.
is_int() Function:
By using this function we can check the input variable is an integer or not.
(int)variable Function / (integer)variable Function / intval(variable) Function:
By using this function we can convert the input variable into integer data type.
Float Data Type:
This data type represents decimal values.
is_float() Function:
To check input variable is float or not.
(float) Variable Function:
Convert the input variable into a floating point.
String Data Types:
A string is a collection of characters. In PHP we can create a string variable in three ways:
Using Single Quotation
Using Double Quotation
Using heredoc Syntax
Heredoc:
This syntax we are using to display HTML content through PHP script to avoid the problem with a single and double quotation which should go for heredoc syntax.
Compound Data Types:
Array:
An array comes under a compound data type using to store multiple values.
Object:
An object is an instance of class comes under a compound data type.
Special Data Type:
Resource Data Type:
Resource data type prefers external resource like database connection, ftp connection, etc.
Null Data Type:
In PHP null is not a value, we can consider a variable as a null variable based on three conditions:
If the variable is not set with any value.
If the variable is set with null.
If a value of the variable is unset.
is_null() Function:
By using this function we can check the variable is null or not.
Data Types in PHP
Reviewed by Abdul iTech
on
Saturday, April 13, 2019
Rating:
No comments: