Is there a quick way to combine one arrays values as the other array's keys?
Input:
array A => Array (
[0] => "cat"
[1] => "bat"
[2] => "hat"
[3] => "mat"
)
array B => Array (
[0] => "fur"
[1] => "ball"
[2] => "clothes"
[3] => "home"
)
Expected output:
array C => Array (
[cat] => "fur"
[bat] => "ball"
[hat] => "clothes"
[mat] => "home"
)
How could I do that?
You can do this simply with
array_combine
:Try this:
array_combine($a, $b);
array_combine()
will exactly do what you want.Quoting the manual:
In your case, you'd have to do something like this:
While of course you could also use various combinations of loops to do that,
array_combine()
is probably the simplest solution.