All streams
Search
Write a publication
Pull to refresh
0
0
digi @digi

User

Send message
Правильный набор условий:
if ($number % 100 > 10 && $number % 100 < 20) return $base . $e0;
if ($number % 10 == 1) return $base . $e1;
if ($number % 10 >= 2 && $number % 10 <= 4) return $base . $e2;
return $base . $e0;
Буквально сегодня ночью для этих целей написал небольшую функцию Smarty.

Использование:

{ending number=$reviews base="реценз" e0='ий' e1='ия' e2='ии'}
{ending number=$comments base="комментар" e0='иев' e1='ий' e2='ия'}


И сама функция (файл /smarty/libs/plugins/function.ending.php):

function smarty_function_ending($params, &$smarty)
{
// ...
// проверки входных параметров пропущены
// ...

$base = !isset($params['base']) ? '' : $params['base']:

$e0 = $params['e0'];
$e1 = $params['e1'];
$e2 = $params['e2'];
$number = $params['number'];

if ($number % 10 == 1) return $base . $e1;
if ($number % 10 >= 2 && $number % 10 <= 4) return $base . $e2;
return $base . $e0;
}
</code>
2

Information

Rating
Does not participate
Location
Украина
Date of birth
Registered
Activity