How To Array Merge In PHP?

03-Apr-2023

.

Admin

How To Array Merge In PHP?

Hi guys,

Today i am explained to the how to use how to merge array in php. This article will give you simple two example of array merge in php. I will help for you in this example of merge array in php.

This example to i will show to two array mearge in without any loop .I am used mearge array in array_mearge() function is used in mearge array in php.

Let's get started to the example.

Solution


$output = array_merge($array1, $array2);

Example

$array1 = [

'divyang' => 'vadodariya',

'dharmik' => 'tank',

];

$array2 = [

'savan' => 'rathod',

'mehul' => 'bagada',

];

$output = array_merge($array1, $array2);

dd($output);

Output

array:4 [?

"divyang" => "vadodariya"

"dharmik" => "tank"

"savan" => "rathod"

"mehul" => "bagada"

]

i hope it can help you...

#PHP 8

#PHP