By the way are there any examples on how to use PHP within Code field?
For instance, is <?php necessary or it is added automatically?
PHP opening tag is not necessary. Aside from that just use PHP as normally. When using substitutions in your code be sure to always treat them as strings.