PHP Function generating comma separated lists
function comma_separate ($input, $joiner = 'and') {
$input = array_unique($input);
$output = $input[0];
if(count($input)==1)
return $output;
for($a=1;$a<(count($input)-1);$a++)
$output .= ', '.$input[$a];
$output .= ' '.$joiner.' '.$input[count($input)-1];
return $output;
}
A snippet of PHP to share with you to that creates comma separated lists. This function takes an array of elements and a final joining word such as 'and' or 'or', and returns a string.