laravel集合函数—each()
each() 用于迭代集合中的每个元素$collection = collect(['one', 'two', 'three', 'four']);
$data = [];
$collection->each(function($item, $key) use(&$data) {
// 满足条件则 停止迭代
if($item == 'three' || $key == 2) {
return false;
}
$data[] = $item;
});
return $data; // ["one","two"]
页:
[1]