Last active
August 29, 2015 14:06
-
-
Save gekh/a5c0a2bd7ea4ce7eec58 to your computer and use it in GitHub Desktop.
Pluralizer. Форма слова в зависимости от числа с количеством
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 | |
class WordHelper | |
{ | |
/** | |
* Форма слова в зависимости от числа с количеством | |
* | |
* Пример использования: | |
* echo $n." ".plural($n, "письмо", "письма", "писем")." у Вас в ящике"; | |
* | |
* @return mixed | |
*/ | |
static public function pluralize($n, $form1, $form2, $form5) | |
{ | |
$n = abs($n) % 100; | |
$n1 = $n % 10; | |
if ($n > 10 and $n < 20) return $form5; | |
else if ($n1 > 1 and $n1 < 5) return $form2; | |
else if ($n1 == 1) return $form1; | |
return $form5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment