In PHP, how do I concatenate arrays in Laravel?

In Laravel, you can concatenate arrays using various methods. Below is an example of how to do it using the `array_merge()` function and the `+` operator. You can also use the Collection methods provided by Laravel for more advanced operations.

Example of Array Concatenation in Laravel

<?php // Using array_merge() $array1 = ['apple', 'banana']; $array2 = ['orange', 'grape']; $mergedArray = array_merge($array1, $array2); print_r($mergedArray); // Using the plus operator $array3 = ['a' => 'apple', 'b' => 'banana']; $array4 = ['c' => 'orange', 'd' => 'grape']; $concatenatedArray = $array3 + $array4; // Note: This keeps the keys from array3 print_r($concatenatedArray); // Using Laravel Collections $collection1 = collect(['apple', 'banana']); $collection2 = collect(['orange', 'grape']); $mergedCollection = $collection1->merge($collection2); print_r($mergedCollection->all()); ?>

php laravel concatenate arrays array merge array concatenation laravel collections