Here’s a comma separated string function which uses the serial comma properly with a conjunction in a list. e.g. apple, berry, ice cream => apple, berry and ice cream. It’s essentially a natural language join:

public static function natural_language_join(array $list, $conjunction = 'and') {
$last = array_pop($list);
if ($list) {
return implode(', ', $list) . ' ' . $conjunction . ' ' . $last;
}
return $last;
}

You can customize the conjunction to any word you need.

Support this site, share this page:Tweet about this on TwitterShare on RedditShare on LinkedInShare on FacebookEmail this to someone