Hello. There was a problem that I can not solve. For example, there is an array of 500 data. And I want to break them down by 100. In order for section 1 to get from 0 to 100, to section 2 from 101-200 and so on. How can this be solved? Google, but did not find the answer.

Thank.

    2 answers 2

    For example, split by 5:

    $array = array(1, 2, 3, 4, 5, 6); var_dump(array_chunk($array, 5)); 

    Documentation http://php.net/manual/ru/function.array-chunk.php

    • Thank you very much! Helped a lot! - Denis Maksiura

    If it is from an array, then

     $array500 = [....]; // Массив из 500 элементов $section1 = array_slice($array500, 0, 100); $section2 = array_slice($array500, 100, 100); // и т.д. 

    http://php.net/manual/ru/function.array-slice.php

    • You lose 100 elements, correct, replace 101 with 100 . - Manitikyl
    • yes, thank you)))) - Dmitry Kozlov