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 Twitter

Twitter

Share on Reddit

Reddit

Share on LinkedIn

Linkedin

Share on Facebook

Facebook

Email this to someone

email