How can the comparison of two numbers be visually highlighted in a PHP foreach loop?
When comparing two numbers in a PHP foreach loop, you can visually highlight the comparison by adding a conditional statement within the loop to check if the current number matches the number you are comparing it to. If they match, you can apply a CSS class to visually highlight the comparison, such as changing the background color or adding a border.
<?php
$numbers = [3, 7, 2, 9, 5];
$compareNumber = 7;
echo "<ul>";
foreach ($numbers as $number) {
if ($number == $compareNumber) {
echo "<li style='background-color: yellow;'>$number</li>";
} else {
echo "<li>$number</li>";
}
}
echo "</ul>";
?>