3
Two scripts with the same result:
Example 1:
<?php
...códigos PHP acima...
$tabela = '<table>';
$tabela .= '<tr>';
$tabela .= '<th> Valor1 </th>';
$tabela .= '<th> Valor2 </th>';
$tabela .= '<th> Valor3 </th>';
$tabela .= '</tr>';
$tabela .= '<tr>';
$tabela .= '<td>' . $valor1 . '</td>';
$tabela .= '<td>' . $valor2 . '</td>';
$tabela .= '<td>' . $valor3 . '</td>';
$tabela .= '</tr>';
$tabela .= '</table>';
echo $tabela;
...códigos PHP abaixo...
?>
Example 2:
<?php
...códigos PHP acima...
?>
<table>
<tr>
<th> Valor1 </th>
<th> Valor2 </th>
<th> Valor3 </th>
</tr>
<tr>
<td> <?= $valor1 ?> </td>
<td> <?= $valor2 ?> </td>
<td> <?= $valor3 ?> </td>
</tr>
</table>
<?
...códigos PHP abaixo...
?>
I would like to know if there are, and what, the advantages and disadvantages among the above examples.
For example: I think to treat everything in a variable to then print, would occupy more memory and processing, because there is concatenation and space in memory (especially if we consider in large ties).
Point that raised the question:
Error due to over-calculation
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)
Downvoter, comment on why -1, so I can improve the question.
– rbz
To think: and you think that in the second example the HTML will be stored where, since in the first one would be in memory?
– Woss
I think I expressed myself badly. It would be the case of the memory of the variable, which exhausts: example
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)
. Were the two forms equal? Now confused me!– rbz