title: PHP - split arrays if value 2 is higher than 1 (
body: <p>I have worked hard this night to figure out how to split my arrays into a lot of arrays, defined by a value in the array</p>
  
  <p>I could have this value</p>
  
  <pre><code>$array = array ( 
      array ("Apple", 10),
      array("Ball", 5) 
  );
  </code></pre>
  
  <p>Then I want Apple to have 10 arrays where the value is "Apple", and Ball to have 5 arrays where the value is "Ball"</p>
  
  <p>Then I came up with this, but the output seems pretty strange..</p>
  
  <pre><code>$newarray = array();
  foreach($array as $val):
      for($i = 1; $i &lt;= $val[1]; $i++):
          $newarray[$i] = $val[0];
      endfor;
  endforeach;
  
  print_r($newarray);
  // Array ( [0] =&gt; Ball [1] =&gt; Ball [2] =&gt; Ball [3] =&gt; Ball [4] =&gt; Ball [5] =&gt; Ball [6] =&gt; Apple [7] =&gt; Apple [8] =&gt; Apple [9] =&gt; Apple [10] =&gt; Apple )
  </code></pre>
  
  <p>Hope you guys understand my question, and hope some one can figure it out.</p>
  
  <p>In advance, thanks.</p>