1/*
2 * The merge method merges the given array or collection with the original collection.
3 * If a string key in the given items matches a string key in the original collection,
4 * the given items's value will overwrite the value in the original collection:
5 */
6$collection = collect(['product_id' => 1, 'price' => 100]);
7$merged = $collection->merge(['price' => 200, 'discount' => false]);
8$merged->all(); // ['product_id' => 1, 'price' => 200, 'discount' => false]
9
10// If the given items's keys are numeric, the values will be appended to the end of the collection:
11$collection = collect(['Desk', 'Chair']);
12$merged = $collection->merge(['Bookcase', 'Door']);
13$merged->all(); // ['Desk', 'Chair', 'Bookcase', 'Door']
1$collection = collect(['product_id' => 1, 'price' => 100]);
2
3$merged = $collection->merge(['price' => 200, 'discount' => false]);
4
5$merged->all();
6
7// ['product_id' => 1, 'price' => 200, 'discount' => false]
1$collection = collect(['John Doe']);
2
3$concatenated = $collection->concat(['Jane Doe'])->concat(['name' => 'Johnny Doe']);
4
5$concatenated->all();
6
7// ['John Doe', 'Jane Doe', 'Johnny Doe']
1$collection = collect(['name', 'age']);
2
3$combined = $collection->combine(['George', 29]);
4
5$combined->all();
6
7// ['name' => 'George', 'age' => 29]