Scary Posted January 1, 2009 Share Posted January 1, 2009 I'm a little new to PHP, although I can muddle my way through it OK. I was hoping for some direction converting the function below to loop through 3 different variables in order when called, e.g. tr1, tr2, tr3. Any help will be gratefully appreciated. function cellColor($i, $tdEven = "tdEven", $tdOdd = "tdOdd") { return ($i%2) ? $tdOdd : $tdEven; } Happy 2009! Link to comment https://forums.phpfreaks.com/topic/139068-new-to-php/ Share on other sites More sharing options...
xtopolis Posted January 1, 2009 Share Posted January 1, 2009 This might help get you there. switch($i % 3){ case 0: $class = 'one'; break; case 1: $class = 'two'; break; default: $class = 'thr'; break; } Example: <html> <head> <style> td { width: 100px; } tr.one { background-color: #FF3333; } tr.two { background-color: #33FF33; } tr.thr { background-color: #3333FF; } </style> </head> <body> <table> <?php for($i=0; $i < 30; $i++){ switch($i % 3){ case 0: $class = 'one'; break; case 1: $class = 'two'; break; default: $class = 'thr'; break; } echo "<tr class='$class'>"; echo "<td>Testing</td>"; echo "</tr>"; } ?> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/139068-new-to-php/#findComment-727354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.