1

I have an array in a variable which contains about 700 names. Iterating over the 700 names can be an issue since the array is large and could cause delay so i want to use chunk to see if it there will be no delay in my application.

In my code below, when i run the application, it throws the error

Call to a member function chunk() on array - Laravel

Is it possible i could chunk the data into pieces and iterate over the pieces so the application does not hang due to large data ?

PS: I am new to laravel PHP and sorry for my bad english.

Controller.php

 $myData =  $arrayList->chunk(ceil(($arrayList->count())/5));
       foreach($chunks as $chunk){
           Log::info('Chunking My Data');
           Log::info($chunk);
       }
1

1 Answer 1

2

You can use the native array_chunk function, for example:

$myData = range(1, 10000);
foreach (array_chunk($myData, ceil(count($myData)/5)) as $chunk) {
    var_dump($chunk);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.