note 92825 modified in language.operators.logical by danbrown
| From: | danbrown@php.net | Date: | Tue, 11 Aug 2009 01:59:04 +0000 |
| Subject: | note 92825 modified in language.operators.logical by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159303@lists.php.net to get a copy of this message | ||
If you ever need to alternate row colors for data output in a table, do this:
in your CSS put these two classes:
.dataRow1 { background-color: #DFDFDF; }
.dataRow2 { background-color: #FFFFFF; }
then in your PHP, loop over each row:
<?php
// ....
foreach ($foo_array as $foo) {
?><tr class="<?php echo ($dr = !$dr) ? "dataRow1" : "dataRow2";
?>"><td><?php echo $foo
?></td></tr><?php
}
?>
No need to initialize $dr as by default PHP will make it a boolean "false", then each
iteration, it will toggle true/false and substitute the CSS class
--was--
If you ever need to alternate row colors for data output in a table, do this:
in your CSS put these two classes:
.dataRow1 { background-color: #DFDFDF; }
.dataRow2 { background-color: #FFFFFF; }
then in your PHP, loop over each row:
foreach ($foo_array as $foo) {
?><tr class="<?= ($dr = !$dr) ? "dataRow1" : "dataRow2"
?>"><td><?= $foo
?></td></tr><?php
}
No need to initialize $dr as by default PHP will make it a boolean "false", then each
iteration, it will toggle true/false and substitute the CSS class
http://php.net/manual/en/language.operators.logical.php