title: PHP global declaration
body: <p>I'm using PHP's global declaration to make an array available to a number of functions in a script.  The variable is declared at the top of the script and is referenced with global in each of the functions which uses it, as follows:</p>
  
  <pre><code>&lt;?php
  
  $myarray = array(1, 2, 3);
  
  function print_my_array() {
      global $myarray;
  
      print '&lt;ul&gt;';
      foreach($myarray as $entry) {
          print '&lt;li&gt;'.$entry.'&lt;/li&gt;';
      }
      print '&lt;/ul&gt;';  
  
      return 0;
  }
  
  print_my_array();
  
  ?&gt;
  </code></pre>
  
  <p>Sometimes, but not always, the array is not set when the function is called, generating an error when the foreach is called.  In the actual code, the array used is given a very unique name and so should not be causing any collisions with anything else.  Am I mis-using the global declaration?</p>