Skip to content
Advertisement

Keep duplicate keys when fill keys for multilevel arrays

im trying to fill values from array1 as keys for array2 but i got problem if keys are duplicate:

JavaScript

result i got:

JavaScript

I need it like this:

JavaScript

Modified output I want now: (after looking all comments/answer)

JavaScript

Thank you!

Advertisement

Answer

1st solution : You cannot get what you want as same indexes in php array got over-write:https://3v4l.org/r934K

What best possible you can get is:

JavaScript

Output: https://3v4l.org/DfPU3

2nd soultion : For the output what you want, you need to apply one more foreach()

JavaScript

Output : https://3v4l.org/u8JmX

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