Combine two arrays with duplicate keys

I need to combine two arrays with duplicate keys and keep the duplicates

My current function works for the part where it's a straight ahead combine with no multi-dimensional arrays (the else in the if/else block)... but as soon as I try to make a mutli-dimensional array my end result is nothing. I end up with an array that is empty.

are you sure you're actually passing arrays to the function and not strings containing lists? Because that's what the single-dimensional variant expects (which is weird), so I guess you've simply stumbled upon your own coding and messed up the test values.

Why canít I use certain words like "drop" as part of my Security Question answers?
There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

are you sure you're actually passing arrays to the function and not strings containing lists? Because that's what the single-dimensional variant expects (which is weird), so I guess you've simply stumbled upon your own coding and messed up the test values.

With arrays, you should get a correct result.

.......Wow.... How did I not see that. Thank you.

Just in cast anybody comes along looking to do something similar... this is what I did to fix it:

I moved this part up to the top of the function to generate the array from the comma separated list.

The first problem is that your function doesn't do what it says. It's called dataArrayCombine(), but it does not combine two arrays. Instead, it expects two CSV strings -- which is a bad way of implementing lists, by the way. The second problem is that it's too specialized. You can't use it for anything but your special CSV strings. If you simply wanna combine two ordinary arrays, you can't do that (unless you turn them into strings first).

Confusing code is bad code, because it's almost guaranteed to cause misunderstandings and bugs. This is obvious if you're working in a team. But even if you're doing this just for fun and you're the only one who'll ever work on the code, it's still important to do it properly. Because after a year or maybe even a month, you won't remember all quirks, pitfalls and tricks. And then your dataArrayCombine() function is probably the first thing you'll stumble upon.

Rewrite the function so that it takes two arrays. Or at least rename it.

Why canít I use certain words like "drop" as part of my Security Question answers?
There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".