I know it seems basic, but I wrote this a while ago and use it in many many applications I’ve written. I’m surprised alot of languages don’t have something this simple in a small, native function…
Takes three arguments: number, singular and plural.
Basically, if number is plural (!= 1), return plural, else return singular, as per the following PHP code:
function plural($num, $singular, $plural) {
if ($num != 1) return $plural;
return $singular;
}
Useful when writing copy that needs to read correctly, eg: You have 0 credits; You have 1 credit; You have 2 credits.
You could write:
print "You have " . plural($num, "$num credit", "$num credits");
*shrug* I like it.