Created
February 13, 2016 09:40
-
-
Save d1i1m1o1n/0d060f76a3fd2e869252 to your computer and use it in GitHub Desktop.
Вывести правильное окончание слова "товар" в зависимости от количества добавленных товаров в корзину (например, 1 товар, 3 товара, 5 товаров)
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
<? | |
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; | |
} | |
?> | |
<?=$num?> <?=getNumEnding($num, Array("товар", "товара", "товаров"))?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment