Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
array of objects vs array of arrays
<?php
// 10
// 20
// 20
// 40
dd(collect([
[
'id' => 1,
'price' => 10
],
[
'id' => 1,
'price' => 20
],
])->each(function($item){
$item['price']=$item['price']*2;
return $item;
}),collect([
(object)[
'id' => 1,
'price' => 10
],
(object)[
'id' => 1,
'price' => 20
],
])->each(function($item){
$item->price=$item->price*2;
return $item;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment