title: Looping through PHP array in foreach and give each $value a new variable name
body: <p>I want to take an array, loop it with a foreach loop, and have each array value be sent through a class to get data from a database. This is the code I am currently using:</p>
  
  <pre><code>foreach ($unique_category as $key =&gt; $value) 
  {
      $category = $value;
      $value = new database;
      $value-&gt;SetMysqli($mysqli);
      $value-&gt;SetCategory($category);
      $value-&gt;query_category();
      ${"$value_category"} = $value-&gt;multi_dim_array();
      print_r(${"$value_category"});
      echo "&lt;br /&gt;&lt;br /&gt;";            
  }
  print_r($unique_category[0]."_category");
  </code></pre>
  
  <p>I want the variable <code>$unique_category[0]."_category"</code> to be <code>${"$value_category"}</code>.
  Currently, the <code>${"$value_category"}</code> in the foreach loop prints out the correct value/array, while <code>$unique_category[0]."_category"</code> just prints person_category (person being the first value in that array). </p>
  
  <p>How would I go about making <code>$unique_category[0]."_category"</code> print the same thing as <code>${"$value_category"}</code>?</p>
  
  <p>Thank you</p>
  
  <p>EDIT:</p>
  
  <p>The foreach loop is making a multidimensional array that looks something like this <code>Array ( [0] =&gt; Array ( [0] =&gt; Home [1] =&gt; 9.8 ) [1] =&gt; Array ( [0] =&gt; Penny [1] =&gt; 8.2 ))</code> I want to be able to print out this array outside the foreach loop, with each md array having its own variable name so I can print them out wherever and whenever I want.</p>