settingsAccountsettings
Menusettings

Q: Numbers from 1 to 20 in PHP

+3 votes

Write a PHP script to print the numbers from 1 to 20:

  • Print the numbers in a list <ul><li>…</li></ul>
  • Print odd lines in blue, even lines in red
asked in PHP category by user eiorgert

1 Answer

0 votes
 
Best answer

Here's the answer:

<!DOCTYPE html>
<html>
<head>
    <title>Hello PHP</title>
</head>
<body>
<ul>
    <?php
    for ($i = 1; $i <= 20; $i++) {
        if ($i % 2 == 1) {
            echo "<li><span style='color: blue'>$i</span></li>";
        } else {
            echo "<li><span style='color: green'>$i</span></li>";

        }
    }
    ?>
</ul>
</body>
</html>

 

answered by user golearnweb
selected by user golearnweb
...