Just out of curiosity, I am wondering what the more experienced coders here would consider best practice for jumping in and out of PHP code in a web page. I generally prefer to keep my PHP and HTML in larger blocks, but some people like to use the <?php ?> tags like they were going out of style.
For example, do you prefer this?
<?php
if ($table == "Forecasted") {
?>
<td align="center" style="font-weight:bold; font-size:10pt">Dispose Project</td>
<?php
}
?>
<?php
if ($table == "Hold") {
?>
<td align="center" style="font-weight:bold; font-size:10pt">Retrieve Project</td>
<?php
}
?>
Or, this?
if ($table == "Forecasted")
{
echo '<td align="center" style="font-weight:bold; font-size:10pt">Dispose Project</td>\n';
}
if ($table == "Hold")
{
echo '<td align="center" style="font-weight:bold; font-size:10pt">Retrieve Project</td>\n';
}
There's no question that the 2nd example is much more readable code, but there are always trade-offs. In this case, what you gain on the code view side would be lost somewhat in the resulting HTML view.
The "PHP Bible" is fairly silent on the issue. Is there a best-practice here?