It turns out the way you called the function tabuada
, it is being interpreted as a string:
$tabela .= '<td>tabuada (10)</td>';
As its function tabuada
already makes the impression using echo
, simply call for the table to be displayed:
tabuada(10);
However this clear, would be far from being printed inside the table
.
For the table to be printed inside the table, its function tabuada
needs to be changed and the rest of the code too... There are many ways to do this, below an example trying to keep your code:
<?php
function tabuada($tabuada){
$cont = 1;
$resultado = '';
while ($cont <= 10){
$resultado .= '<tr><td>' . $tabuada . 'x' . $cont . ' = ' . ($tabuada * $cont) . '</td></tr>';
$cont++;
}
return $resultado;
}
$tabela .= '<center><table border="1";>';
$tabela .= tabuada(10);
$tabela .= '</table></center>';
echo $tabela;
?>
Now its function tabuada
returns a string, containing the tabs already inside the tags tr
and td
, with this we create to invoke the function tabuada
and concatenate its return to the rest of the code that generates the table
.
The element
<center>
is obsolete.– Augusto Vasques