title: PhP variable declared in a loop and I would like to store it in a global array
body: <p>Im new to PHP and would like to get some advice on the following situation:</p>
  
  <p>I have a file in which Im parse an XML file. My strategy has been create a "parser.php" file. Then create separate files for each tag in the XML file. Each of these separate files is a class that when instantiated will store all the attributes of that particular tag. </p>
  
  <p>I have several loops in the parser that instantiate the class that corresponds with the tag when they encounter it.Once the loop is done that object is then inserted into a global array.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;?php
  include ('class.Food.php');
  include ('class.Drink.php');
  $xml = simplexml_load_file("serializedData.xml");
  
  //Global Variables==============================================================
  
  $FoodArray = array();
  $DrinkArray = array();
  $FoodObj;
  $DrinkObj;
  
  foreach($xml-&gt;children() as $child)
  {
  //Instantiate a Food object here and insert into the array
  $FoodObj = new Food();
  //Add attributes of tag to the Food object
  array_push($FoodArray, $FoodObj);
  
  }
  </code></pre>
  
  <p>Thus at the end of each loop there would be a food object created and that would be added to the FoodArray.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Do I have to explicitly call a destructor or free the object memory at the end of the loop?</li>
  <li>Using the above syntax, will the FoodObj be stored in the FoodArray as a reference or a value</li>
  <li>Each time the variable Food gets a different instance stored in it, does that matter when stored in the array? All the objects stored in the array go by the index number right? </li>
  </ol>
  
  <p>Thanks</p>