Skip to content

Instantly share code, notes, and snippets.

@nccdr
Created January 11, 2018 06:09
Show Gist options
  • Save nccdr/8b2732d929db7eecd70989120c8b7ed5 to your computer and use it in GitHub Desktop.
Save nccdr/8b2732d929db7eecd70989120c8b7ed5 to your computer and use it in GitHub Desktop.
<?php
// $apps = 103;
// getNumEnding($apps, ['приложение', 'приложения', 'приложений']);
function getNumEnding($number, $endingArray)
{
$number = $number % 100;
if ($number >= 11 && $number <= 19) {
$ending = $endingArray[2];
} else {
$i = $number % 10;
switch ($i) {
case (1):
$ending = $endingArray[0];
break;
case (2):
case (3):
case (4):
$ending = $endingArray[1];
break;
default:
$ending = $endingArray[2];
}
}
return $ending;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment