简体   繁体   中英

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

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);
       }

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM