Last active
February 19, 2016 13:15
-
-
Save nook-ru/a3f35eba7e5940b1f3c2 to your computer and use it in GitHub Desktop.
Форма множественного числа от количества
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 | |
/** | |
* Возвращает нужную форму множественного числа в зависимости от количества | |
* | |
* Пример вызова: | |
* pluralForm(1, ["рубль", "рубля", "рублей"]); | |
* | |
* @param float|int $number Число | |
* @param string[3] $titles Подписи для 1, 3 и 5 | |
* @param bool $includeNumber Включать число в результат | |
* @return string | |
*/ | |
function pluralForm($number, $titles, $includeNumber = true) | |
{ | |
$cases = array (2, 0, 1, 1, 1, 2); | |
return ($includeNumber ? $number.' ' : '').$titles[ ($number%100>4 && $number%100<20)? 2 : $cases[min($number%10, 5)] ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment