knackforge
July 3, 2013
The topic looks so simple, isn't it? It looked simple to me when I ran into such a kind of need. The first and foremost PHP function that I thought to get this done was array_combine. It did produce the desired result, the below piece of code shows my implementation,
I sent back the requirement packing and moved to my next assignment, but after a couple of days, I was quite pestered about the performance factor of my implementation. What would happen if the size of the array is going to cross N? I had no answer to my own question, To stir up my baffling I came across this question in StackExchange. What looked like a perfect solution in minutes looked like a well-executed coding mishap!
array_combine having O(n) can never be trusted in all cases, once the array size goes beyond what the server can actually bear the results would be disastrous. Hence I looked into another alternate solution that would work great in any condition. The following piece of code shows the correct version of my implementation,
The above code just iterates through one of my arrays, based on this array's key the second array's value is retrieved. Hope this helps someone as it did in my case.
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!