Add



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.

    $num1=23;
    $num2=56;

    function myAdditionFunction()
    {
    // To access global variable within a local function, $GLOBALS is being used.
    $GLOBALS['sum']=$GLOBALS['num1']+$GLOBALS['num2'];
    } 

    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,

$name=array("Omer","Javed");

Second one is Associate Array. For example,

$name=array("FName"=>"Omer","LName"=>"Javed");

Third one is Multi-dimensional array.