phpfunctioncodeigniteralternator

How to reset codeigniter alternator() function


How do I set an alternator to its inicial position?

Code:

foreach($items as $item):
        foreach($sides as $side):
            echo alternator('Left', 'Right');
        endforeach;
        //I want the alternator to "restart" here and always start from the initial variable "Left" in this case
endforeach;

Solution

  • Note: To use multiple separate calls to this function simply call the function with no arguments to re-initialize.

    foreach($items as $item):
            foreach($sides as $side):
                echo alternator('Left', 'Right');
            endforeach;
            alternator();
    endforeach;