php globals
<?php
// Demonstrate how to declare global variable
// Declaring global variable
$x = "hi,";
$y = " ankur";
$z = " here.";
// Display value
// Concatenating String
echo $x.$y.$z;
?>
// output
hi, ankur here.
<?php
// global variable inside using global keyword
// Declaring global variable
$x = "hi,";
$y = " ankur";
$z = " here.";
$a = 100;
$b = 50;
function showname(){
//using global keyword
global $x, $y, $z;
return $x.$y.$z;
}
function addition(){
// using GLOBALS['variable name']
$GLOBALS['b'] = $GLOBALS['a'] + $GLOBALS['b'];
}
// printing output
echo showname()."\n";
addition();
echo $b;
?>
//output
hi, ankur here.
150