Skip to content
Advertisement

Zip multiple arrays in PHP based on their identical keys and not their indices or their positions in array

I have two arrays:

JavaScript

note that in $b Array ‘three’ and ‘two’ keys are not in same order as $a. also ‘six’ key is not available in $b Array.

I want this result as output:

JavaScript

I tried to use array_map but it don’t detect keys and just zip them based of their indices:

JavaScript

Advertisement

Answer

Can’t you just use ksort(). Then, create a new array using `foreach’?

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement