I have a single array such as this:
array('one','two','three','four','five','six','seven')
I’m using a foreach to iterate through this and I’d like to build an array like this:
array(
array('one'),
array('two')
),
array(
array('three'),
array('four')
),
array(
array('three'),
array('five')
),
array(
array('six'),
array('seven')
)
Any suggestions on how do this?
Thanks!
Use array_chunk.
From the PHP Manual:
In your case you need
$output_array = array_chunk($input_array, 2);And then if you want to convert the leaves to arrays: