<?
/////////////////////////////////////////////////////////////////
// Склонение слов
/////////////////////////////////////////////////////////////////
function plural_wordform($num, $form_for_1, $form_for_2, $form_for_5){
$num = abs($num) % 100;
$num_x = $num % 10;
if ($num > 10 && $num < 20)
return $form_for_5;
if ($num_x > 1 && $num_x < 5)
return $form_for_2;
if ($num_x == 1)
return $form_for_1;
return $form_for_5;
}
// Проверка на числах
foreach(array(12, 23, 1, 4, 5, 16, 21, 20, 0) as $num){
echo $num." ".plural_wordform($num, 'товар','товара','товаров');
echo "<hr>";
}