i have written this code and I got the point of its first function. I was practicing while looking at this screenshot from w3schools.
I request only some good and clear explanation regarding the second and the third function.
I have edited the code according to the differences seen in the code and its results.
<?php
$x = 5;
$y = 10;
function myTest1(){
global $x, $y;
$y = $x + $y;
echo "test1 value using GLOBAL keyword INSIDE function is : $y <br>";
}
myTest1();
echo "test1 value using GLOBAL keyword OUTSIDE function is : $y <br><br>";
?>
<?php
$x = 5;
$y = 10;
function myTest2(){
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
echo "test2 value using NO GLOBAL with GLOBALS[variable/index] keyword INSIDE function is nothing : $y <br>";
}
myTest2();
echo "test2 value using NO GLOBAL with GLOBALS[variable/index] keyword INSIDE function is : $y <br><br>";
?>
<?php
$x = 5;
$y = 10;
function myTest3(){
global $x, $y;
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
echo "test3 value using GLOBAL with GLOBALS[variable/index] keyword INSIDE function is : $y <br>";
}
myTest3();
echo "test3 value using NO GLOBAL with GLOBALS[variable/index] keyword INSIDE function is : $y <br>";
?>