PHP supports eight data types:

·         Integer

·         Float

·         String

·         Boolean

·         Array

·         Object

·         Null

·         Resource

PHP integer 

An integer data types is a non-decimal number  between -2,147,483,648 and 2,147,483,648.They correspond to simple whole numbers , both positive and negative.

Integers can be specified in three formats:

·         Decimal(10-based),

·         Hexadecimal(16-based-prefixed with 0x)

·         Octal(8-based-prefixed with 0)

In the following examole $y is an integer:

Var_dump($y); // This function returns the data type and value






PHP String:

A string is a sequence of character,Following is a valid string example:


echo $a;</br>//echo function is used to print
echo $b;



PHP Float

Floating point numbers are also called as double.It has a decimal point or exponential number.

Following is a valid float example:




PHP Boolean:

A boolean has two values:true or false.


PHP Array

An array is a data structure that store one or more similar type of values in 0ne variable.For example if you want to store 5  numbers in one variable you can use array.


var_dump($x); // This function returns the data type and value


array(5) { [0]=> string(3) "Ram" [1]=> string(5) "Shyam" [2]=> string(4) "Neha" [3]=> string(6) "Shikha" [4]=> string(7) "Shalini" }

 PHP Null

Null data type is a variable in which no value is assigned.

It can only have one value: Null


var_dump($a); // This function returns the data type and value




 PHP Object

In PHP,object must be declare explicitly.

Following is a valid object example:


class text{
    function text(){
        $this->model = "Hello world";
$text=new text();// create an object
var_dump($text); // show object properties


object(text)#1 (1) { ["model"]=> string(11) "Hello world" } 

PHP Resource

The special resource type is not an actual data type. It is the strong of a reference to functions and resources external to PHP.

Decision Making

The if..else..elseif are used to take decision based on some conditions.

This is how decision making statements works:

There are three types of decision making statements:

If..else:Code is executed if condition is true and another code if condition is false.Let’s see some example:

echo("if condition is executed");
   echo("else condition is executed");

If condition is executed

Elseif:this statement is used when you have to execute some code if one of the several conditions are true.


         $d = date("D");
         if ($d == "Sat")
            echo "Have a nice weekend!";
         elseif ($d == "Sun")
            echo "Have a nice Sunday!";
            echo "Have a nice day!";


Have a nice weekend! 

Switch Statement:The switch statement is used to avoid long blocks of if..elseif code.

$name = "Ram";
switch ($name) {
    case "Ram":
        echo "My name is Ram!";
    case "blue":
       echo "My name is Shyam!";
    case "green":
        echo "My name is Rakhi!";
        echo "Your name is neither Ram,Sham nor Rakhi!";



My name is Ram!

  Modified On Dec-18-2017 06:41:48 AM

Leave Comment