PHP Variables and Data Types

PHP Variables

PHP variable starts with dollar ($) sign. For example, $max.

How to Declare PHP Variable?

In PHP, there is no way to separately declare a variable. We assign a value to the variable, at that time it is declared as well depending on the type of value assigned to it. For example, $num = 10;

PHP Variables Scope

There are three scope of PHP variable. First one is local. Second is global. Third and the last is static.


    function myAdditionFunction()
    // To access global variable within a local function, $GLOBALS is being used.

    myAdditionFunction ();
    echo $sum;

PHP Data Types

PHP Integers

Integers are numbers without decimal point. For example, $num=50;

PHP Floating Point

Integers are numbers with decimal point or having exponential form. For example, $fpval=2.5;

PHP Boolean

It can have one of two values i.e. true, false. For example, $bval = true;

PHP Array

It is to store multiple values into a single variable. There are three types of array.
First one is Indexed Array. For example,


Second one is Associate Array. For example,


Third one is Multi-dimensional array.

4.5 out of 5 based on 13 user ratings