I need to convert a string into a set of arrays of a fixed length.
Example: input: 1111122222333333
I need output of
[0] =>
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 1
[1] =>
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => 2
The following code works great:
for ($x = 0; $x < count($codedDataArray) - $colWidthSum + 1; $x += $colWidthSum + 1) {
for ($c = 0; $c <= $colWidthSum; $c++) {
$rows[$j][] = $codedDataArray[$z];
$z++;
}
$j++;
}
but it runs out of memory when I give it really large strings, say 10959 bytes.
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?
EDIT 1: I'm running out of memory on both preg_split and str_split 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.
EDIT 2: The string length is actually 745,982 bytes, I was looking at the compressed length.
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!