我正在尝试删除集合中的一个项目,我正在尝试检查当前集合项目的特定值是否等于下一个集合项目,如果相同则删除下一个集合。
$path = CanvasPath::where('stream_id', $streamId)->get();
// if in collection $path a value ->path is identical to previous or before remove it
foreach($path as $key => $value) {
$collection = $path->getIterator();
$current = current($collection);
$next = next($collection);
if($current->path == $next->path) {
// remove $next collection
}
}
如何删除该项目?
答案 0 :(得分:0)
做独特
$path = CanvasPath::where('stream_id', $streamId)->get();
$path = $path->map(function ($array) {
return collect($array)->unique('id')->all();
});