Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedHelalAhmed/16e6e6ce46b1e641128d919fab672a4b to your computer and use it in GitHub Desktop.
Save AhmedHelalAhmed/16e6e6ce46b1e641128d919fab672a4b to your computer and use it in GitHub Desktop.
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