阅读(562)
赞(5)
Laravel 8 each() {#collection-method}
2021-07-01 14:28:56 更新
each
方法用于循环集合项并将其传递到回调函数中:
$collection->each(function ($item, $key) {
//
});
如果你想中断对集合项的循环,那么就在你的回调函数中返回 false
:
$collection->each(function ($item, $key) {
if (/* some condition */) {
return false;
}
});