Can you add a comment about what this does?
What if there are no more items in the $map array, will that cause an infinite loop?