031 - local and global
Variable x inside function : 10
Variable x outside function : 10
Variable y outside function : 2015
<?php // 031 - local and global echo "</br><span class='myheading'>031 - local and global</span></br>"; $x_031 = 10; $y_031 = 20; function test_031() { global $x_031; /* can be used directly usin keyword - Global */ echo "Variable x inside function : $x_031 <br>"; //echo "Variable y outside function will print nothing : $y_031 <br>"; // can't access directly (error ) } test_031(); echo "Variable x outside function : $x_031 "."</br>"; echo "Variable y outside function : $y_031"; // another example $x_a_031 = 5; $y_a_031 = 10; function test_a_031() { global $x_a_031, $y_a_031; $x_a_031 = $x_a_031 + $y_a_031; } test_a_031(); echo $x_a_031; ?>