Just an update to a five-year-old post: just got kicked in the ass by the exact same problem on PHP7.4.
One would expect that the $key/$value vars on a foreach loop should fall out of scope after its done.
Or at the very least, when a foreach loop is created, either an error would be thrown when trying to use already-existing-vars for key/val or the variables would be restarted from scratch (any old ones would automatically be unset).
Just an update to a five-year-old post: just got kicked in the ass by the exact same problem on PHP7.4.
One would expect that the $key/$value vars on a foreach loop should fall out of scope after its done.
Or at the very least, when a foreach loop is created, either an error would be thrown when trying to use already-existing-vars for key/val or the variables would be restarted from scratch (any old ones would automatically be unset).