title: PHP slice array into parts
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2861530/php-split-array-into-smaller-even-arrays">php split array into smaller even arrays</a>  </p>
  </blockquote>
  
  
  
  <p>How can I slice an array into multiple parts ? Lets say I have this array:</p>
  
  <p><code>$arr = range(1, 15);</code></p>
  
  <p>How can I end up with this result :</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; 1
              [1] =&gt; 2
              [2] =&gt; 3
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; 4
              [1] =&gt; 5
              [2] =&gt; 6
          )
  
      [2] =&gt; Array
         ............
  )
  </code></pre>
  
  <p>What I've tried so far : </p>
  
  <pre><code>$parts = 3;
  $slices = array();
  
  for($i=0; $i&lt;($parts * $parts); $i=$i+$parts){
    $sliced = array_slice($arr, $i, (count($arr) / $parts));
    array_push($slices, $sliced);
  }
  </code></pre>
  
  <p>It seems to be working fine <b> only with arrays under 10 elements </b> that makes me confused about why and how that code works really, it doesn't seem static to me as well.. Is there any other way to do it or a fix for the code?</p>