Well it really depends what you're doing, I like to group together my PHP code with relevant parts in the HTML, for example if I have a form that executes some PHP code on the same page I will have the PHP just after the form HTML so that I know what it relates to.
In some cases, you have to put PHP code within the HTML when you echo something for example, for it to be in the correct div.
If you had:
PHP Code:
<html>
<div id="menu">
<?php getMenuItems(); ?>
</div>
</html>
You'd have to keep that specific code there, because if you moved it to a different location, the menu items would end up in a different part of the document.
Like if you tried to put that code in here:
PHP Code:
<html>
<head>
<title><?php getMenuItems(); ?></title>
</head>
</html>
This should be fairly obvious, but it's going to mess up your page.
There is no disadvantage to putting all your PHP code at the top, bottom or interlaced within the HTML, your script won't run any faster or slower. For readability however, I think it's best if you group PHP and HTML together where they're relevant.
Bookmarks