Skip to content

Instantly share code, notes, and snippets.

@erochest
Forked from jeremyboggs/multiple_creators.php
Created July 31, 2012 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erochest/3219133 to your computer and use it in GitHub Desktop.
Save erochest/3219133 to your computer and use it in GitHub Desktop.
Changes how creators are listed depending on their numbers
<?php
/**
* One Creator: "Jane Doe"
* Two creators: "Jane Doe and John Doe"
* Three creators: "Jane Doe, John Doe, and Jim Doe"
* Four or more: "Jane Doe et al."
*/
if ($creators) {
$numCreators = count($creators);
if ($numCreators > 3) {
$cite .= $creators[0] . ' et al., ';
} else {
$separator = ' and ';
if ($numCreators == 3) {
$separator = ', and ';
}
$cite .= join($separator, array_filter(array_merge(array(join(', ', array_slice($creators, 0, -1))), array_slice($creators, -1)))) . ', ';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment