Please note, this is a STATIC archive of website technosmarter.com from 20 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
 

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
• 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 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 .


Example


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

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 .

Example


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

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=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 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.

Example


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

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:-


Ecommerce system in PHP website | Digital Ecommerce Shop web app

$66



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

$39



Integrate Payumoney payment gateway in PHP website | Source Scripts

$12




0 Comment