Easiest way to alternate row colors in PHP/HTML?

前端 未结 19 1958
無奈伤痛
無奈伤痛 2020-12-01 03:41

Here\'s a PHP example of mine. Can anyone find a shorter/easier way to do this?


    
19条回答
  •  时光说笑
    2020-12-01 04:17

    Fundamentally - no. That's about as easy as it gets. You might rewrite it a bit shorter/cleaner, but the idea will be the same. This is how I would write it:

    $c = true; // Let's not forget to initialize our variables, shall we?
    foreach($posts as $post)
        echo '$post
    ";

提交回复
热议问题