“Array Merge Laravel” Réponses codées

php array_merge


<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
Array
(
    [color] => green
    [0] => 2
    [1] => 4
    [2] => a
    [3] => b
    [shape] => trapezoid
    [4] => 4
)
Alberto Peripolli

Array Merge Laravel

// From PHP 7.4, you can use the spread syntax to merge arrays in PHP like JavaScript
$firstArray = ['a' => 'life', 'b' => 'ball'];
$secondArray = ['c' => 'History'];

$thirdArray = [...$firstArray, ...$secondArray];

// you can still use the array_merge function

$thirdArray = array_merge($firstArray, $secondArray);
KingUche

PHP Merge 2 tableaux

<?php
  $array1 = [
      "color" => "green"
  ];
  $array2 = [
      "color" => "red", 
      "color" => "blue"
  ];
  $result = array_merge($array1, $array2);
?>

// $result
[
    "color" => "green"
    "color" => "red", 
    "color" => "blue"
]
TheDutchScorpion

Fusionner deux tableau (Laravel)

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

Irfan

Laravel fusionne deux tableaux d'assistance

Arr::add()
The Arr::add method adds a given key / value pair to an array if the given key doesn't already exist in the array or is set to null:

use Illuminate\Support\Arr;

$array = Arr::add(['name' => 'Desk'], 'price', 100);

// ['name' => 'Desk', 'price' => 100]

$array = Arr::add(['name' => 'Desk', 'price' => null], 'price', 100);

// ['name' => 'Desk', 'price' => 100]
Excited Elephant

Réponses similaires à “Array Merge Laravel”

Questions similaires à “Array Merge Laravel”

Plus de réponses similaires à “Array Merge Laravel” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code