Created
August 27, 2012 19:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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