Last active
August 8, 2022 18:11
-
-
Save scottnunemacher/7b6a16d3ecf64a8ca12dd88803698df1 to your computer and use it in GitHub Desktop.
PHP - Test a value and return plural if needed.
This file contains 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 get_plural($value, $singular, $plural = NULL){ | |
if($value == 1){ | |
return $singular; | |
} else { | |
if(!isset($plural)){ | |
$plural = $singular.'s'; | |
} | |
return $plural; | |
} | |
} | |
echo get_plural(4, 'car'); // Outputs 'cars' | |
/* Can supply plural term. */ | |
echo get_plural(8, 'goose', 'geese'); // Outputs 'geese' | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment