PHP – Transform a table with values ​​generated by for $i / for $j into a variable

Question:

Good afternoon everyone. I have a form that shows the fields in table form:

echo "<table style='text-align: center; widtd: 280pt;' border='1'>";
    // Cabeçalho da tabela:
    echo '<tr><td>AAA</td><td>BBB</td><td>CCC</td><td>DDD</td><td>EEE</td></tr>';
    for ($i=0; $i<3; $i++){ 
        echo "<tr>"; 
        for ($j=0; $j<4; $j++){            
            if (($i==0) && ($j==0)){
                echo "<td style='text-align: center; widtd: 100pt;'>AA</td>";                 
            }
            if ($i==0) {
                echo "<td><input name='linhaum$j'></td>";
            }

            if (($i==1) && ($j==0)){
                echo "<td style='text-align: center; widtd: 100pt;'>BB</td>";                
            }
            if ($i==1) {
                echo "<td><input name='linhadois$j'></td>";
            }

            if (($i==2) && ($j==0)){
                echo "<td style='text-align: center; widtd: 100pt;'>CC</td>";               
            }
            if ($i==2) {
                 echo "<td><input name='linhatres$j'></td>";
            }            
        }
        echo "</tr>";
    }
    echo "</table><br>";

I'm receiving this form like this:

echo '<table style="text-align: center; widtd: 280pt;" border="1">';
    echo '<tr><td>AAA</td><td>BBB</td><td>CCC</td><td>DDD</td><td>EEE</td></tr>';
    for ($i=0; $i<3; $i++){ 
        echo '<tr>';
        for ($j=0; $j<4; $j++){            
            $linhaum = $_POST["linhaum$j"];
            $linhadois = $_POST["linhadois$j"];
            $linhatres = $_POST["linhatres$j"];

            if (($i==0) && ($j==0)){
                echo '<td style="text-align: center; widtd: 100pt;">AA</td>';                 
            }
            if ($i==0) {
                echo "<td>$linhaum</td>";
            }

            if (($i==1) && ($j==0)){
                echo '<td style="text-align: center; widtd: 100pt;">BB</td>';                
            }
            if ($i==1) {
                echo "<td>$linhadois</td>";
            }

            if (($i==2) && ($j==0)){
                echo '<td style="text-align: center; widtd: 100pt;">CC</td>';               
            }
            if ($i==2) {
                 echo "<td>$linhatres</td>";
            }            
        }
        echo '</tr>';
    }
echo '</table><br>';

What I need: Convert this table, already filled with the captured data, into a variable.

Example of what I need:

$minhavar = "a tabela que foi preenchida com os valores do formulário";
[...];
echo $minhavar;

Grateful!

Answer:

thank you, however, i already got the solution:

$equipe = '<table style="text-align: center; widtd: 280pt;" border="1">';
    $equipe .= '<tr><td>AAA</td><td>BBB</td><td>CCC</td><td>DDD</td><td>EEE</td></tr>';
    for ($i=0; $i<3; $i++){ 
        $equipe .= '<tr>';
        for ($j=0; $j<4; $j++){            
            $linhaum = $_POST["linhaum$j"];
            $linhadois = $_POST["linhadois$j"];
            $linhatres = $_POST["linhatres$j"];

            if (($i==0) && ($j==0)){
                $equipe .= '<td style="text-align: center; widtd: 100pt;">AA</td>';                 
            }
            if ($i==0) {
                $equipe .= "<td>$linhaum</td>";
            }

            if (($i==1) && ($j==0)){
                $equipe .= '<td style="text-align: center; widtd: 100pt;">BB</td>';                
            }
            if ($i==1) {
                $equipe .= "<td>$linhadois</td>";
            }

            if (($i==2) && ($j==0)){
                $equipe .= '<td style="text-align: center; widtd: 100pt;">CC</td>';               
            }
            if ($i==2) {
                 $equipe .= "<td>$linhatres</td>";
            }            
        }
        $equipe .= '</tr>';
    }
$equipe .= '</table><br>' ;

echo $equipe;
Scroll to Top