Can you put a line of HTML within a PHP for loop?

Am I able to run a line of HTML code within a PHP loop? If so how do I go about it?

Demonstrated below:

for ($x = 0; $x <= count($names); $x++) {
    $value = implode(', ', $names[$x]);
    <a href="tracking.php" class="btn btn-primary"><?=$value;?></a>
}

Answer

Yes you can, but you either have to leave PHP, or echo the HTML like this:

for ($x = 0; $x <= count($names); $x++) {
    $value = implode(', ', $names[$x]);
    echo '<a href="tracking.php" class="btn btn-primary">' . $value . '</a>';
}

Leave a Reply

Your email address will not be published. Required fields are marked *