combine() method combines the values of the collection as key with the value of another array of collection, also you can say that combine one array key with other array values, using the laravel collection combine method you can easy to merge array value with the key to merge the value with other PHP array value.
Sometimes developers need to combine() the one array value with another array key that the time array collection method combines use.
Also you can say that array merge, two or multiple arrays store into single array that time need to combine collection method.
Here below working example that will help you to understand how to use combine method in laravel collection.
Please refer following working example that will help you to understand the use of combined array collection in laravel.
Example 1: Use simple array
$data = [ 'key-1', 'key-2', 'key-3', ]; $data1 = [ 'value-1', 'value-2', 'value-3', ]; $collection = collect($data)->combine($data1); // OUTPUT Illuminate\Support\Collection {#6768 ▼ #items: array:3 [▼ "key-1" => "value-1" "key-2" => "value-2" "key-3" => "value-3" ] }
EXAMPLE 2: Use with array first() method
$data = [ 'key-1', 'key-2', 'key-3', ]; $data1 = [ 'value-1', 'value-2', 'value-3', ]; $collection = collect($data)->combine($data1)->first(); // OUTPUT // "value-1"
EXAMPLE 3: Use with toArray() method
$data = [ 'key-1', 'key-2', 'key-3', ]; $data1 = [ 'value-1', 'value-2', 'value-3', ]; $collection = collect($data)->combine($data1)->toArray(); // OUTPUT array:3 [▼ "key-1" => "value-1" "key-2" => "value-2" "key-3" => "value-3" ]
EXAMPLE 4: Use with Multidimensional array
$data = [ 'key-1', 'key-2', 'key-3', ]; $data1 = [ ['value-1' => 123,'value-4' => 456], ['value-2' => 852,'value-5' => [1,2,3,4,56]], 'value-3', ]; $collection = collect($data)->combine($data1); // OUTPUT Illuminate\Support\Collection {#6768 ▼ #items: array:3 [▼ "key-1" => array:2 [▼ "value-1" => 123 "value-4" => 456 ] "key-2" => array:2 [▼ "value-2" => 852 "value-5" => array:5 [▼ 0 => 1 1 => 2 2 => 3 3 => 4 4 => 56 ] ] "key-3" => "value-3" ] }
By understand above example to use combine method in laravel collection.
We always thanks to you for reading our blogs.

Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Error : You need to install the imagick extension to use this back end
- How to Make/Create/Write JSON File Using PHP Array In Laravel - PHP
- Email Send Using Queue In Laravel
- How To Filter In Laravel Query Example
- Laravel Database Based Dynamic Mail Configuration Set Example
- Laravel OneSignal Push Notification Integrate
- All Know About Different Root Path Of The Laravel Application With Example
- Laravel 10 Arr::pluck() Helper Function Use Example
- Laravel 10 Horizon Integration Tutorial Example
- How to Integrate PayUMoney Payment Gateway in Laravel 9