Search code examples
zend-frameworkhelperzend-view

Is Zend_View_Helper_Cycle efficient?


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?


Solution

  • 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.