Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Variant of the numeral
- *
- * @param array word in three variant (1, 2, 5)
- *
- * @return string string for current numeral
- *
- * @example variantNumeral(array('materiał', 'materiały', 'materiałów'), 5) => 5 materiałów
- **/
- function variantNumeral(array $words, $num) {
- $num_m1 = $num % 100;
- if ($num_m1 == 1 && $num < 100) {
- $word = $words[0];
- } else {
- $num_m2 = $num_m1 % 10;
- if (($num_m2 > 1 && $num_m2 < 5) && ($num_m1 < 12 || $num_m1 > 14)) {
- $word = $words[1];
- } else {
- $word = $words[2];
- }
- }
- return $num . ' ' . $word;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement