Skip to content

Instantly share code, notes, and snippets.

@daler445
Created July 1, 2018 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daler445/e3ef0b805a68fe2baacda6ccc267a40d to your computer and use it in GitHub Desktop.
Save daler445/e3ef0b805a68fe2baacda6ccc267a40d to your computer and use it in GitHub Desktop.
Определение окончания слова в зависимости от числа
<?php
function getNumberEnding($number, $variations) {
$cases = array(2, 0, 1, 1, 1, 2);
return $variations[($number % 100 > 4 && $number % 100 < 20) ? 2 : $cases[min($number % 10, 5)]];
}
echo getNumberEnding(733, array('рубль', 'рубля', 'рублей'));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment