title: Converting a string to a set of array with fixed length
body: <p>I need to convert a string into a set of arrays of a fixed length.</p>
  
  <p>Example: input: <code>1111122222333333</code></p>
  
  <p>I need output of</p>
  
  <pre><code>[0] =&gt;
      [0] =&gt; 1
      [1] =&gt; 1
      [2] =&gt; 1
      [3] =&gt; 1
      [4] =&gt; 1
  [1] =&gt;
      [0] =&gt; 2
      [1] =&gt; 2
      [2] =&gt; 2
      [3] =&gt; 2
      [4] =&gt; 2
  </code></pre>
  
  <p>The following code works great:</p>
  
  <pre><code>    for ($x = 0; $x &lt; count($codedDataArray) - $colWidthSum + 1; $x += $colWidthSum + 1) {
  
          for ($c = 0; $c &lt;= $colWidthSum; $c++) {
              $rows[$j][] = $codedDataArray[$z];
              $z++;
          }
          $j++;
      }
  </code></pre>
  
  <p>but it runs out of memory when I give it really large strings, say 10959 bytes.</p>
  
  <p>Is there a built-in PHP function I'm missing that will do the same thing, or am I just going to have to deal with the memory issues?</p>
  
  <p>EDIT 1: I'm running out of memory on both <code>preg_split</code> and <code>str_split</code> as well, so I'm probably doing something really wrong. I'll still mark as answered, as soon as I figure out what my initial issue was in the first place.</p>
  
  <p>EDIT 2: The string length is actually 745,982 bytes, I was looking at the compressed length.</p>
  
  <p>EDIT 3: I think the string is just too big. I'll have to see if there as a way of breaking it up without losing data since that's actually a small example and it's actually binary data. Thanks for the answers everyone!</p>