What’s the difference between the following two pieces of code? Version B seems harder to read, with excessive use of open and closing tags, but I find a lot of tutorials and examples using this format. Is there a preferred approach, meaning a procedural reason for one over the other, or is this personal preference?
Version A (enclosed in php)
<?php
$test = array('a','b','c');
if (isset($test))
{
echo '<div id="testmessage">
<h2>
Test Message Below
</h2>
<ul>';
foreach ($test as $t)
{
echo '<li>'.$t.'</li>';
}
echo '</ul>';
echo '</div>';
}
?>
Version B (Multiple open and closing tags)
<?php $test = array('a','b','c');
if (isset($test)){
?>
<div id="testmessage">
<h2>
Test Message Below
</h2>
<ul>
<?php
foreach ($test as $t)
{
?>
<li><?php echo $t; ?></li>
<?php
}
?>
</ul>
</div>
<?php
}
?>
No real difference, but it is just not encouraged.
And I give you version C which might read a little better than B: