Simplified foreach variable naming as there is no chance of collisions with PHP code
Fixed PHP 'foreach' statement implementation to copy arrays before iteration to allow nested loops

- This will cause a performance hit (should be copy-on-write) but works for now.