I love serial commas (putting a comma before “and” in a list. I.e. one, two, and three). People call them old-fashioned and clunky, but they really help with clarity (see this article for an example).
The thing I don’t like about serial commas is trying to automate their formatting. I can’t find examples anywhere, so here’s my PHP code to do it. The way I use it is a while() loop after querying a database, but it will work with any loop (i.e. a foreach’d array). $num_authors is the total number of records. $count_authors is set to 1 before the loop.
The code
if ($num_authors == 1)
{
echo $author;
}
else
{
if ($num_authors > $count_authors)
{
if (($count_authors + 1) == $num_authors)
{
if ($num_authors == 2)
{
echo "$author and ";
}
else
{
echo "$author, and ";
}
}
else
{
echo "$author, ";
}
}
elseif ($num_authors == $count_authors)
{
echo $author;
}
else
{
// error message
}
$count_authors++;
}