Skip to content

Instantly share code, notes, and snippets.

@mgerring
Created August 27, 2012 19:25
Show Gist options
  • Save mgerring/3491525 to your computer and use it in GitHub Desktop.
Save mgerring/3491525 to your computer and use it in GitHub Desktop.
Humanizes a list, in the form of an array, by adding commas and the word "and". No Oxford commas, because fuck you.
<?php
function humanize($array) {
while(count($array) > 0) {
$output .= array_pop($array);
if(count($array) > 1) {
$output .= ', ';
} elseif(count($array) > 0) {
$output .= ' and ';
}
}
echo $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment