How to combine two arrays together?

array_combine() will exactly do what you want.

Quoting the manual:

array array_combine ( array $keys , array $values )

Creates an array by using the values from the keys array as keys and the values from the values array as the corresponding values.

In your case, you’d have to do something like this:

$array['C'] = array_combine($array['A'], $array['B']);

While of course you could also use various combinations of loops to do that, array_combine() is probably the simplest solution.

Leave a Comment