L!MP, Так не проще:
/*
-----------------------------------------------------------------
Правильные окончания
-----------------------------------------------------------------
*/
function completions($str = '', $array = '')
{
$rest = substr($str, -1);
if ($rest == 1) {
$out = $array[0];
} else
if ($rest == 1 or $rest == 2 or $rest == 3 or $rest == 4) {
$out = $array[1];
} else {
$out = $array[2];
}
return $out;
}Пример:
echo completions($count, array('сообщение', 'сообщения', 'сообщений'));