Add Array To Another Array In Laravel Collection

[Solved] Add Array To Another Array In Laravel Collection | Php Frameworks Laravel - Code Explorer | yomemimo.com
Question : add array to another array in laravel collection

Answered by : mohamad-shahkhajeh

$collection = collect(['product_id' => 1, 'price' => 100]);
$merged = $collection->merge(['price' => 200, 'discount' => false]);
$merged->all();
// ['product_id' => 1, 'price' => 200, 'discount' => false]

Source : | Last Update : Wed, 09 Mar 22

Answers related to add array to another array in laravel collection

Code Explorer Popular Question For Php Frameworks Laravel