How can a counter variable be used in PHP to control the output of HTML elements like <tr> and <td>?

To control the output of HTML elements like <tr> and <td> in PHP, a counter variable can be used to determine when to start or stop displaying these elements. By incrementing the counter variable within a loop, you can conditionally output the HTML elements based on the value of the counter.

&lt;?php
// Example of using a counter variable to control HTML elements
$numRows = 5; // Number of rows to display

echo &#039;&lt;table&gt;&#039;;

for ($i = 1; $i &lt;= $numRows; $i++) {
    echo &#039;&lt;tr&gt;&#039;;
    echo &#039;&lt;td&gt;Row &#039; . $i . &#039;, Column 1&lt;/td&gt;&#039;;
    echo &#039;&lt;td&gt;Row &#039; . $i . &#039;, Column 2&lt;/td&gt;&#039;;
    echo &#039;&lt;/tr&gt;&#039;;
}

echo &#039;&lt;/table&gt;&#039;;
?&gt;