-1

I am creating a table with zebra style in my view:-

$sr_no = 1;
if($sr_no % 2 == 0){
  $style = 'class="even-row"';
    }else{
          $style = 'class="odd-row"';
         }
    <tr <?php echo $style?>>
    $sr_no++;

Zend Framework provides this

echo $this->cycle(array("class='even-row'","class='odd-row'"))->next();

However, I think, behind the scenes it is doing the same as my code. So which one is Optimised?

vascowhite
  • 18,120
  • 9
  • 61
  • 77
Edward Maya
  • 429
  • 2
  • 10
  • 25

2 Answers2

1

Well, that depends on your use case doesn't it? Your code will work in very simple cases, but Zend_View_Helper_Cycle can cope with more complex requirements. See the manual.

A quick comparison of your code with the code of Zend_View_Helper_Cycle will tell you that you are trying to compare very different animals.

Whether it is efficient or not depends on what you are trying to do.

vascowhite
  • 18,120
  • 9
  • 61
  • 77
1

If you don't need support for legacy browsers, you can achieve zebra style with CSS

#mytable tr:nth-child(odd) { background: red }
vascowhite
  • 18,120
  • 9
  • 61
  • 77
Boby
  • 826
  • 5
  • 9