D
D
Drembler2018-03-21 21:16:10
PHP
Drembler, 2018-03-21 21:16:10

What is the correct way to output in php?

Should I output everything via echo or is it better to use it only when outputting php variables and functions?
Are there other downsides to using echo all the time besides code readability?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Balintodd, 2018-03-21
@Balintodd

I do this on some occasions! echo analog.
<?=$title?>

O
Oleg, 2018-03-21
@402d

for good, the output to the output stream comes last.
and even the view does not output directly, but returns a response (roughly a string).
templating engines to your liking (I loved smart for a long time, used twig, now back to native style)

<ul>
<?php foreach($list as $row) { ?>
  <li><?= $row->name ?></li> 
<?php } ?>
</ul>

since all these smarts and tweaks are worse understood by ide and autocomplete is lame

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question