alternator()

alternator($args)

Parameters:
  • $args (mixed) – A variable number of arguments
Returns:

Alternated string(s)

Return type:

mixed

Allows two or more items to be alternated between, when cycling through a loop. Example:

1
2
3
4
for ($i = 0; $i < 10; $i++)
{
        echo alternator('string one', 'string two');
}

You can add as many parameters as you want, and with each iteration of your loop the next item will be returned.

1
2
3
4
for ($i = 0; $i < 10; $i++)
{
        echo alternator('one', 'two', 'three', 'four', 'five');
}

Note

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

doc_CodeIgniter
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.