使用 for 循环打印出 1-100 之间的数字 3 的倍数是红色和下划线,5 的倍数是蓝色和斜体

Using for loop to print out numbers between 1-100 multiples of 3 are red and underlined and multiples of 5 are blue and italicized

我在编写 for 循环方面需要帮助。这是我第一次编写 for 循环,但不知道该怎么做。有人可以帮助我吗?

我想做图片里的东西.. - 3 的倍数为红色并带有下划线 - 5 的倍数为蓝色并带有下划线 - 数字乘以 3 和 5 为斜体,下划线和紫色 - 不属于任何类别的数字为黑色和粗体

Numbers from 1-100 with multiples of 3 being red and underlined and 5 blue and underlined

有很多方法可以做到。一种方法是:

  <?php  
     for ($i = 1; $i <= 100; ++$i) {

     $mod3 = $i % 3;
     $mod5 = $i % 5;
     $str = '';
     if (!$mod3) {
       $str = '<p style="color: red;"><u>$i</u></p>';
     }
     if (!$mod5) {
       $str .= '<p style="color: blue;"><u>$i</u></p>';
     }
     if ($mod3 && $mod5) {
       $str .= '<p style="color: purple;"><em>$i</em></p>';
     }
     echo $str, "\n";
    }
?>