Moved PHP code to the beginning

I was getting an "undefined offset" error, which made me think that the
intial php array wasn't present when the page loaded, so I moved the
PHP code to the start of the file, and the error is resolved.