Php: Easy way for creating a Global Function.

Starting php script:

echo 'Lets make a global function';

function createglobal() {

global $my_global;
$my_global = 10;


$my_global = 5;

echo "The value of \$my_global is '$my_global'


echo "The value of \$my_global is '$my_global'

ending php script

Before the createglobal(); is called the value of variable stays to local value. Which is 5. But as soon as the function is called the value becomes to 10 which was defined in the createglobal function.


Post a Comment

Popular posts from this blog

Why is Sachin Tendulkar not the best batsman in the world?

The Legend of Zelda: Breath Of The Wild – What Is Hinox?