0
1

More than 3 years have passed since last update.

PHP 剰余算を使い、行ごとの背景色を変更する

Last updated at Posted at 2020-05-06
sample.php
<table>
  <?PHP
    for($i=1;$i<=100;$i++){
      if($i%2){
        print('<tr style="background-color: #ccc">');
      }else{
        print('<tr>');
      }
        print('<td>'.$i.'行目</td>');
        print('</tr>');
    }
  ?>
</table>

出力
1行目
2行目
3行目
4行目
5行目
6行目
7行目
8行目
9行目
10行目

-奇数行目の背景の色が変更になる
メモ
if($i%2),余りが出るところがtrueとなり,変更される

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1