Tuesday, July 12, 2011

$GLOBALS

$GLOBALS is a super global variable and it is structured like array. Well most of the superglobals are asociative arrays. It contains all user defined variables that are accesible in the global scope.

Here is an example

<?php

$var="Hello";

echo $GLOBALS["var"];
//it will print Hello

function varFunc(){
      $var="Hello world!";
}

varFunc();

echo $GLOBALS["var"];
//it will still print Hello
//Why? Because $var located in the function is a local variable and is //inaccessible. 
?>

No comments:

Post a Comment