As a result of making a web page, a doubt arose. When displaying some type of information on the screen using echo
php, how would it be better to display this data, in terms of efficiency?
Showing everything with a single
echo
:echo '<table><tbody><tr><th></th></tr></tbody></table>';
Showing all with multiple
echo
:echo '<table>'; echo '<tbody>'; echo '<tr>'; echo '<th>'; echo '</th>'; echo '</tr>'; echo '</tbody>'; echo '</table>';
Obviously the ideal is to do a single echo.
You get better performance using single quotes than double quotes, since in double quotes the php interpreter first looks to see if it has to substitute any variables inside the double quotes.
Using variables to store and doing a single echo later is slower than doing multiple echoes without using variables.
In any case, think that we are talking about micro-seconds. So there is no need to complicate much in that regard.
You can see in phpbench.com time comparisons of each of them.