“Fusion de la colección Laravel” Código de respuesta

colecciones de fusión de laravel

/* 
 * The merge method merges the given array or collection with the original collection.
 * If a string key in the given items matches a string key in the original collection,
 * the given items's value will overwrite the value in the original collection:
 */
$collection = collect(['product_id' => 1, 'price' => 100]);
$merged = $collection->merge(['price' => 200, 'discount' => false]);
$merged->all(); // ['product_id' => 1, 'price' => 200, 'discount' => false]

// If the given items's keys are numeric, the values will be appended to the end of the collection:
$collection = collect(['Desk', 'Chair']);
$merged = $collection->merge(['Bookcase', 'Door']);
$merged->all(); // ['Desk', 'Chair', 'Bookcase', 'Door']
Yingfufu

Laravel Collection Concat

$collection = collect(['John Doe']);

$concatenated = $collection->concat(['Jane Doe'])->concat(['name' => 'Johnny Doe']);

$concatenated->all();

// ['John Doe', 'Jane Doe', 'Johnny Doe'] 
Cooperative Crab

Fusion de la colección Laravel

$collection = collect(['product_id' => 1, 'price' => 100]);

$merged = $collection->merge(['price' => 200, 'discount' => false]);

$merged->all();

// ['product_id' => 1, 'price' => 200, 'discount' => false]
Tough Tarsier

Fusionar dos colecciones (Laravel)

$foo = collect(Foo::all());
$bar = collect(Bar::all());
$merged = $foo->merge($bar);

Irfan

Laravel Collection Combine

$collection = collect(['name', 'age']);

$combined = $collection->combine(['George', 29]);

$combined->all();

// ['name' => 'George', 'age' => 29]
Cooperative Crab

Respuestas similares a “Fusion de la colección Laravel”

Preguntas similares a “Fusion de la colección Laravel”

Más respuestas relacionadas con “Fusion de la colección Laravel” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código