The Global keyword is used to get the information of the variable within the function.
Example:
[php]<?php
$x = 5;
$y = 10;
function mddir() {
global $x, $y;
$y = $x + $y;
}
mddir(); // run function
echo $y; // output the new value for variable $y
?>[/php]
In above php code, we have declared the global variable $x
and $y and provided the value of 5 & 10 respectively. To get this value in the php function we have to use the word “global
” as a keyword to get the information from the $x
and $y
.
The word global is reserved as a Global keyword in the php liabrary. you can use the keyword anywhere in the php script to fetch the value of the global variables.