A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function:


SUBMITTED BY: henry1874w

DATE: June 4, 2017, 7:56 p.m.

FORMAT: Text only

SIZE: 236 Bytes

HITS: 211

  1. <?php
  2. function myTest() {
  3. $x = 5; // local scope
  4. echo "<p>Variable x inside function is: $x</p>";
  5. }
  6. myTest();
  7. // using x outside the function will generate an error
  8. echo "<p>Variable x outside function is: $x</p>";
  9. ?>

comments powered by Disqus