D
D
Dmitry Baskakov2018-02-07 13:20:24
PHP
Dmitry Baskakov, 2018-02-07 13:20:24

How to subdivide an array into the same number of elements?

The task is simple, but I just can't process it all and come up with something.
In general, there is an array of paragraphs (roughly speaking) in it an array of lines. And so, it is necessary to enclose each 5 lines in a separate array.
Initially, the array is:
array(
[0]=>value
[1]=>value
...
[n]=>value
)
Should be turned into:
array(
[0]=> array(
[1]=>value
[2] =>value
[n]=>value
)
[1]=> array(...)
...
[n]=> array(...)
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-02-07
@dmitrybascacov

$arrays = array_chunk($array, $n);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question