The global keyword is used to access a global variable from within a function.
To do this, use the global keyword before the variables (inside the function):
<?php
$x = 70;
$y = 7;
function myNum {
global $x, $y;
$y = $x + $y;
}
myNum();
echo $y; // output is 77
?>
by Tornike Kartvelishvili
2 years ago
PHP
Variables
Variables Scope
0
Pro tip: use ```triple backticks around text``` to write in code fences