Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active August 29, 2015 14:14
Show Gist options
  • Save lavoiesl/eacc7f75663c31135d21 to your computer and use it in GitHub Desktop.
Save lavoiesl/eacc7f75663c31135d21 to your computer and use it in GitHub Desktop.
<?php
function implode_oxford(array $pieces)
{
$pieces = array_values($pieces);
switch (count($pieces)) {
case 0:
return '';
case 1:
return $pieces[0];
case 2:
return $pieces[0].' and '.$pieces[1];
default:
$pieces[count($pieces) - 1] = 'and '.$pieces[count($pieces) - 1];
return implode(', ', $pieces);
}
}
@lavoiesl
Copy link
Author

lavoiesl commented Feb 4, 2015

Yeah, yours is cuter ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment