PHP Data Types:-

Techno PHP

Variables store the different type of data that is known as data type 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
• NULL
• 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 .


Example


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

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

Integer :-

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 .


Example


<?php 
$num  = 12000;
var_dump($num );
?>
		
		
Run

Float:

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

Example


<?php 
$num = 20.44;
var_dump($num);
?>
		
		
Run

Boolean:-

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=true;
$x=false ;

Example


<?php 
$x=30;
$y=20;
if($x>$y)
{
echo "X is true greater";
}
else
{
echo "y is true greater";
}
0
?>
		
		
Run

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:

Example


<?php 
$fruits = array("Banana","apple","orange");
var_dump($fruits);
?>
		
		
Run

Object:-

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 .

Example


<?php
class Laptop {
    function Laptop() {
        $this->model = "ispiron";
    }
}

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

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

NULL :-

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.

Example


<?php
$num = "Hello we are testing .";
$num = null;
var_dump($num);
?>
		
		
Run

PHP Resource-: :-

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.

Related