Tuesday 14 August 2018

INSERT AT THE BEGINNING OF AN ARRAY IN PHP

Last week, while programming, I needed to insert an array at the beginning of another. So, since basically I was just merging 2 arrays, I tried to do it like this:
But it didn’t work. 🙁 It was displaying something like:
Not a good result, because the arrays’ keys were actually primary keys used by the RDBMS so it was very important for me to keep the original keys. I didn’t want to take the lame approach and do a foreach loop:
…because it was too obvious, so I did something less obvious, and much more complicated:
But in the end, the most simple and elegant solution:

0 comments:

Post a Comment