I have no idea really how to say this, but I can demonstrate it:
<?php
if (true) {
echo "<h1>Content Title</h1>";
}
?>
vs
<?php if (true) { ?>
<h1>Content Title</h1>
<?php } ?>
What differences are there between the two? Will there be problems caused by not using echo? It just seems super tedious to write echo “html code”; all the time, specially for larger segments of html.
Also, bonus kudos to someone who can rephrase my question better. 🙂
There’s a small difference between the two cases:
Here, because you’re using double quotes in your string, you can insert variables and have their values rendered. For example:
Whereas in your second example, you’d have to have an echo enclosed in a php block:
Personally, I use the same format as your second example, with a bit of a twist:
I find that it increases readability, especially when you have nested control statements.