How to split an array into small arrays?

I have an array with 3200 values. The user selects a number (say 50). I want to split a large array into smaller arrays, each of which contains 50 values ​​(the last contains the remainder).

How do you do this?

+4
source share
3 answers

array_chunk

eg.

$arrays = array_chunk($my_big_array, 50); 
+9
source
 array array_chunk ( array $input , int $size [, bool $preserve_keys = false ] ) 

Check this out: http://php.net/manual/en/function.array-chunk.php

+5
source

Depending on how you want to do this, array_chunk() may be a good place to start.

+3
source

Source: https://habr.com/ru/post/1336476/


All Articles