title: How to deep copy an array in PHP from foreach loop?
body: <p>Here is the php code: </p>
  
  <pre><code>$options_schools = array();
  $options_schools_deepcopy = array();
  
  if (!empty($schools) &amp;&amp; is_array($schools)) {
      foreach ($schools as $key =&gt; $val) {
      $temp_school = $key;
      $options_schools[$temp_school]=$key;    
      }
          $options_schools_deepcopy= $options_schools;
      }
  
  echo form_dropdown('school', $options_schools_deepcopy, '');    
  </code></pre>
  
  <p>I want the array <code>$options_schools_deepcopy</code> to bear the deep copy values of array <code>$options_schools</code> with no reference to it. So, somewhere in the code when array <code>$options_schools</code> becomes null, <code>$options_schools_deepcopy</code> should still have the values originally copied from <code>$options_schools</code> irrespective of where it is accessed in the code. How to achieve it?</p>
  
  <p><strong>Edit1: Please note:</strong>
  As you see from my code, I am trying to make a copy of an array $a into $b while in a if-else condition. I want $b to have the same value of array $a which is assigned when if-else was satisfied. I want $b to retain the copied array anywhere in the code irrespective of it satisfies if-else condition or not and also no matter how array $a changes.</p>
  
  <p><strong>Edit2:</strong>
  if-else does become true but only at a certain point of the code and that is when $options_schools has all the values I need to get copied to $options_schools_deepcopy.</p>