The following code shows how to use local variables as well as global variables in php in PHP Programming.
Variable:
$txt = "Artofcse";
$x = 10;
$y = 15.5;
echo "I love $txt!";
echo "<br/>";
echo "I love " . $txt . "!";
echo "<br/>";
echo $x + $y;
Output:
I love Artofcse!
I love Artofcse!
25.5
Global Variable:
$a = 50;
$b = 100;
function myTest() {
global $a, $b;
$b = $a + $b;
}
myTest();
echo $b;
Output:
150