title: Split an Array into N Arrays - PHP
body: <p>I have an array of 18 values:</p>
  
  <pre><code>$array = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r');
  </code></pre>
  
  <p>I want to split this array into 12 different arrays so it should look like this:</p>
  
  <pre><code>array(
      0 =&gt; array('a', 'b'),
      1 =&gt; array('c', 'd'),
      2 =&gt; array('e', 'f'),
      3 =&gt; array('g', 'h'),
      4 =&gt; array('i', 'j'),
      5 =&gt; array('k', 'l'),
      6 =&gt; array('m'),
      7 =&gt; array('n'),
      8 =&gt; array('o'),
      9 =&gt; array('p'),
     10 =&gt; array('q'),
     11 =&gt; array('r')
  )
  </code></pre>
  
  <p>My function doesn't seem to work</p>
  
  <pre><code>function array_split($array, $parts){
      return array_chunk($array, ceil(count($array) / $parts));
  }
  
  $result = array_split($array, 12);
  </code></pre>
  
  <p>because I get 9 different arrays instead of 12. It would return</p>
  
  <pre><code>array(
      0 =&gt; array('a', 'b'),
      1 =&gt; array('c', 'd'),
      2 =&gt; array('e', 'f'),
      3 =&gt; array('g', 'h'),
      4 =&gt; array('i', 'j'),
      5 =&gt; array('k', 'l'),
      6 =&gt; array('m', 'n'),
      7 =&gt; array('o', 'p'),
      8 =&gt; array('q', 'r')
  )
  </code></pre>
  
  <p>How would I go about doing this? Thanks.</p>