Global vs. Local Variables - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Global vs. Local Variables.php
- <?php
- //global scope
- $x = 10;
- // Define a function
- function var_scope()
- {
- //local scope
- $y=20;
- echo "The value of x is : $x "."<br />";
- echo "The value of y is : $y"."<br />";
- }
- // Call the function
- var_scope();
- echo "The value of x is : $x"."<br />";
- echo "The value of y is : $y ";
- ?>