Sunday, January 17, 2010

A simple implementation for alternate output in PHP

This function was original from Kohana’s Text Helper.

/**
* Alternates between two or more strings.
*
* @param string strings to alternate between
* @return string
*/
public static function alternate()
{
static $i;

if (func_num_args() === 0)
{
$i = 0;
return '';
}

$args = func_get_args();
return $args[($i++ % count($args))];
}



0 Comments: