That is completely different than what I expected the output to be.
I thought that any code (<!DOCTYPE html> as an example) under foreach would be duplicated.
The difference, I've found, is that your html is outside of the foreach() function.
In my code, the html that represents each $item is within the foreach() function.
I modified your code to put the ending } at the end of the print_r()'s and it did what I was expecting (duplicating <!DOCTYPE html>, among others).
I then thought that I might be able to do the same foreach() function twice and that worked.
I'm not sure if it's the best way, but it does get the job done.