2
可以说你有这样的简单集合:如何更改集合中最后一项的值?
$c = collect([
['active'=>false],
['active'=>false],
['active'=>false],
]
);
我想改变的最后一个项目设置活动为true 有没有简单的collectionish的方式,而不是像一些:
$collection->toArray();
$collection[count($collection)-1]['active'] = true;
$newCollection = collect($collection);
感谢这么简单,就像我知道的pop()方法和推(),而不是在我的脑海:) –
它连接使用* last()*方法的操作更少:'$ collection-> last()['active'] = true;' – miikes
使用'last()'可以检索值,但不能修改https:// github。 COM /照亮/支撑/团块/ c371bff488ce3ec3270091d77cf2e825cfeb74f3/Arr.php#L157 –