title: Access a global variable in a PHP function
body: <p>According to the most programming languages scope rules, I can access variables that are defined outside of functions inside them, but why doesn't this code work?</p>
  
  <pre><code>&lt;?php
      $data = 'My data';
  
      function menugen() {
          echo "[" . $data . "]";
      }
  
      menugen();
  ?&gt;
  </code></pre>
  
  <p>The output is <code>[]</code>.</p>