PHP Foreach Preserves Last Item

I thought I’d blog this because it’s something that comes as a surprise to me, so it may come as a surprise to you. Let’s consider this code: http://pastebin.com/mxsjMdij

The second time the loop runs it actually preserves the value of the “$app” variable, and thus triggers the if statement’s isset() function to true.

This issue caught me for a loop for a while, but I guess now I know…. interesting PHP….