Copyright © ashik rahman's Blog
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Wednesday, August 1, 2012

Example of Using Global variable in PHP

See the Code Carefully you can find the Use of Global Variable

<?php
function test() {
$foo = "local variable";

echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
echo '$foo in current scope: ' . $foo . "\n";
}

$foo = "Example content";
test();
?>

The above example will output something similar to:

$foo in global scope: Example content
$foo in current scope: local variable

So we can use Global variable in any function with repeatably changing it's value in a function But Keep the value unchanged outside the function.