PHP Data Types

Variables store the different type of data that is known as data type The various data type has performed a different task. PHP supports many data types written below.

• String
• Integer
• Float (Floating point numbers )
• Boolean (yes or no )
• Array
• Object
• Resource

String Data Type:-

A string is a collection of characters . A string is written between the quotes.You can use single quotes and double quotes .


$x="Hello I am learning PHP";
$y='Learn PHP';
echo $x;
echo "
"; echo $y; ?>

This type of way you can use single and multiple quotes within string .

Integer Data Type in PHP:-

PHP integer is a non-decimal number .
Range of PHP integer :-
2,147,483,648 and 2,147,483,647.
An integer can be either positive or negative .
Integer must not have a decimal point numbers .
An integer must have at least on digit .

Let’s learn with an example .
In bellow example $num is an integer .The PHP var_dump() returns the data type and values .


$num  = 12000;
var_dump($num );

Float Data Type in PHP:

Float Is used for floating point numbers .
Float is a number decimal number that is exponential form (20.44) like this .


$num = 20.44;

Boolean Data Type in PHP:-

Boolean data type represents two states true and false .
Just like we have two $x , $y variables then if we create a condition on these variable so they will be true or false .
$x=false ;


echo "X is true greater";
echo "y is true greater";

Array :-

Array is a collection of similar data items. Array use for store multiple value in single variable .
Here we will take an example of array in which $fruits is a variable of array and
The PHP var_dump() function returns the data type and value:


$fruits = array("Banana","apple","orange");


A Object is a type of data which store the data and information to process all functionality of program .
In PHP, an object must be explicitly declared.
A class is a structure that contains the properties an method .
In other words a class is a collection of functions and methods .


class Laptop {
    function Laptop() {
        $this->model = "ispiron";

// create an new object
$b = new Laptop ();

// Show all properties 
echo $b->model;

NULL Data Type in PHP

A NULL variable is a variable that has no assigned value .
Null is a special data type which can have only one value:

When a variable is created without a value ,It has value of NULL
Let’s learn with an example of NULL.


$num = "Hello we are testing .";
$num = null;

PHP Resource Data Type in PHP-: :-

PHP deals with various types of data like integer, double, string and etc. Resources are also coming under the list of PHP data types. But, unlike other data types, , resource identifiers are acting as a reference or identifier to access resource data provided by a third party external application.

Please Share

Recommended Posts:-

Previous Posts:-

Featured Items:-

Paypal payment form with email, invoice generator in PHP website | Scripts


Certificate system in PHP website | PHP scripts


Student result management system for school and college in PHP website


0 Comment