Skip to content
Advertisement

How to merge two array if one item exist in both array?

I want to expand my city array with post code value. If the city_postcode array contain city array name record then push postcode value into city array. That’s what i want to achive somehow.

city array:

city_postcode array:

The result I want:

Advertisement

Answer

If you can rely on the cities and post codes to be equal in length and sorted, you could just do something like this:

Other wise you could do something more dyanmic like:

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