Please Stop Echoing Things
For my little brother who likes to embedding PHP to html but not sure how to do it nicely.
You probably have ever seen or even written code like below:
<table>
<?php
echo '<td>'.$row->name.'<td>';
echo '<td>'.$row->email.'</td>';
echo '</tr>';
}
?>
</table>
- PHP short echo tag (<?=) is now available forever (PHP version 5.4+)
- PHP have alternative syntax of control structure: http://php.net/manual/en/control-structures.alternative-syntax.php
With those powerful feature, we can rewrite code above little bit more handsome:
<table>
<tr>
<td><?= $row->name; ?></td>
<td><?= $row->email; ?></td>
</tr>
</table>
See ? so what do you think ?
Note, this post already published long time ago in medium: https://medium.com/@eatpraycode/please-stop-echoing-things-1dde8ff57d71