Edy
Edy

Reputation: 35

Laravel join two values from diffrent two array into one array

I have two array from two query. I want to join two array into one array. Example:

Array1

[
   {
       fakultas: "Ekonomi dan Bisnis"
   },
   {
       fakultas: "Hukum"
   }
]


Array2

[
   {
       jumlah_wisudawan: "55"
   },
   {
       jumlah_wisudawan: "17"
   }
]

How to join two array above into one array like this:

[
   {
       fakultas: "Ekonomi dan Bisnis",
       jumlah_wisudawan: "55"
   },
   {
       fakultas: "Hukum",
       jumlah_wisudawan: "17"
   }
]

Please help me, thanks before.

Upvotes: 0

Views: 2860

Answers (2)

Jrey
Jrey

Reputation: 1638

You should use array_merge not array_combine

array_merge($array1, $array2);

See documentation of PHP array_combine vs. array_merge

Upvotes: 1

Abdul Rahman A Samad
Abdul Rahman A Samad

Reputation: 1152

You could use collections:

https://laravel.com/docs/5.4/collections

$collection = collect($array1, $array2);

and if you want to get that array, you can do it like this:

$collection->all();

Upvotes: 1

Related Questions