-1

I have a large binary number stored as a string in a variable. Something like this :

10111100100001010101010101010100000111111111001010101...

I want to split it in chunks of 8, so I use this : chunk_split($text, 8); but chunk_split() returns a string.

How do I store all the chunks in an array ?

icodebuster
  • 8,890
  • 7
  • 62
  • 65
Mayank Kumar
  • 59
  • 1
  • 7

1 Answers1

7

If you want the 8 bits stored as a string within the array use:

str_split($text, 8);

Or, the bits themselves can be chunked as a set of arrays:

array_chunk(str_split($str), 8);
Expedito
  • 7,771
  • 5
  • 30
  • 43