简体   繁体   English

调用数组上的成员 function chunk() - Laravel

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

I have an array in a variable which contains about 700 names.我在一个变量中有一个数组,其中包含大约 700 个名称。 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.迭代 700 个名称可能是一个问题,因为数组很大并且可能导致延迟,所以我想使用块来查看它是否在我的应用程序中没有延迟。

In my code below, when i run the application, it throws the error在下面的代码中,当我运行应用程序时,它会引发错误

Call to a member function chunk() on array - Laravel调用数组上的成员 function chunk() - 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. PS:我是 laravel PHP 的新手,抱歉我的英语不好。

Controller.php 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:你可以使用原生的array_chunk function,例如:

$myData = range(1, 10000);
foreach (array_chunk($myData, ceil(count($myData)/5)) as $chunk) {
    var_dump($chunk);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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