Added pluralize function

Takes a word and a variable and determines if the word should be plural. Optionally returns the variable prepended to the output. Happy Fucking New Year!
This commit is contained in:
Josh Sherman 2012-12-31 20:33:43 -05:00
parent fe0fd407cf
commit 42fc4704c6
2 changed files with 60 additions and 0 deletions

View file

@ -113,6 +113,36 @@ class String
return false;
}
// }}}
// {{{ Pluralize
/**
* Pluralize
*
* Based on a passed integer, the word will be pluralized. A value of zero
* will also pluralize the word (e.g. 0 things not 0 thing).
*
* @static
* @param string $string the word to plurailze
* @param integer $count the count to interrogate
* @param boolean $both (optional) include count in return
* @return string pluralized word
*/
public static function pluralize($string, $count, $both = false)
{
if ($count != 1)
{
$string .= 's';
}
if ($both)
{
$string = $count . ' ' . $string;
}
return $string;
}
// }}}
// {{{ Random