$array1 = array('red', 'green', 'blue'); $array2 = array('yellow', 'orange', 'purple'); $result = array_merge($array1, $array2); print_r($result);
Array ( [0] => red [1] => green [2] => blue [3] => yellow [4] => orange [5] => purple )
$input1 = array('username' => 'john', 'password' => 'secret'); $input2 = array('email' => 'john@example.com', 'phone' => '555-1234'); $result = array_merge($input1, $input2); print_r($result);
Array ( [username] => john [password] => secret [email] => john@example.com [phone] => 555-1234 )In this example, we have two input arrays that contain information about a user. We use the input merge function to combine these two arrays into a single result array. Package library: The input merge function is part of the PHP core library and does not require any additional package or library.