Variable and Types

Variable that holds the data which is temporary with a certain memory location.

$username = "Abhishek ";


Numeric variables:
Variables don’t contain just strings-they can contain numbers too.If we return to the matchbox analogy,to store the number 17 in the variable $count ,the equivalent would be placing say,17

$count = 17;
you can also use a floating point number
$count = 17.5;

Local variable:
local variable are variables that are created within,and can be accessed only by a function.they are generally temporary variables that are used to store partially processed results prior to the function’s return.

$temp = "the date is";
echo $temp.longdate(time());
function longdate($timestamp)
return date("L F JS Y"$timestamp);
output will be toady's time

Global variables:
There are cases when you need a variable to have global scope,because you want all your code to be able to access it.Also,some data may be large and complex,and you don’t want to keep passing it as arguments to functions.

global $is_logged_in;

Static variables:
Static variables are accessible only within the function that declared them but retain their value over multiple calls.

i.e A function is using static variable
function test()
static $count=0;
echo $count;

super global variable:
the super global variables which means that they are provided by the PHP environment but are global within the program

i.e $came_from=$_SERVER["HTTP_REFERER"];

Translate »