PHP doesn't know or care about HTML comments (unless you are using a DOM/HTML parser to parse HTML). It runs any code inside code blocks and just outputs stuff outside of code blocks directly to STDOUT without any regard for what it is.
Just put your code between <?php
and ?>
as normal. The comments will not stop it executing.