Tuesday 26 February 2013

PHP:Variables scope

Lecture #4

Hi!
guys today i want to talk about the the PHP variable scope
so here we go.........................................................................................
There are four scope of php variables
  1. Local
  2. global
  3. static
  4. parameter
so i discuss one by one below as:

     1.Local scope

If any variable declare in the function of php then we say that it's life is affilicate with the php function and it's scope is local .not accessible from the out side the php function
like as

<?php
$n=10;//global scope


 function myfun()
{$h=7;//local scope of the variable


}
myfun();

 ?>

Static scope of variable


<?php
 function myfun()
{
static $n=0;//static scope of variable and static declaration
echo $n;
$n++;

}
myfun();
myfun();
myfun();


?>

parameter scope

<?php
 function myfun($x)
{
echo $x;

}

myfun(5);
?>



for learning subscribe my blog feed..




1 comment: