我有这样一个集合:
Collection {#750 ▼
#items: array:18 [▼
18 => User {#691 ▶}
19 => User {#696 ▶}
20 => User {#701 ▶}
]
}
18、19、20应该有所不同
我尝试进行调用
$collection->get(0);
$collection->get(1);
$collection->get(2);
但显然,它不起作用。
我找到了一个变通方法,使用shift返回第一个元素并将其从集合中删除。
$el1 = $collection->shift();
$el2 = $collection->shift();
$el3 = $collection->shift();
但是在这种情况下,我的原始收藏已被破坏。
有什么想法我该怎么做?