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.

Name: Global vs. Local Variables fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of Global vs. Local Variables.php

  1. <?php
  2. //global scope
  3. $x = 10;
  4.  
  5. // Define a function
  6. function var_scope()
  7. {
  8. //local scope
  9. $y=20;
  10. echo "The value of x is :  $x "."<br />";
  11. echo "The value of y is :  $y"."<br />";
  12. }
  13.  
  14. // Call the function 
  15. var_scope();
  16. echo "The value of x is :  $x"."<br />";
  17. echo "The value of y is :  $y ";
  18. ?> 
  19.  
  20.  
  21.  
File Description
  • Global vs. Local Variables
  • PHP Code
  • 19 Aug-2019
  • 297 Bytes
You can Share it: