I have an array like the following
Array ( [0] => ‘txt1’ [1] => ‘txt2’ [2] => ‘txt3’)
I have another array like it but with different content : Array ( [0] => on [2] => on)
The aim is to get a final array with the keys of the second and the content of the first, it’s like merging them.
So that the final result is : Array ( [0] => ‘txt1’ [2] => ‘txt3’) It would be better to change the keys to 0 – 1, but that a trivial issue, let’s focus on merging them one to one.
The easiest way to do this is with
array_intersect_key(See the PHP Docs). It grabs the values from the first array passed corresponding to the keys present in all other arrays passed.So, your example would look like this:
prints: