A
A
Anton2017-10-17 17:01:06
PHP
Anton, 2017-10-17 17:01:06

How to make number declension in php?

<?if ($arResult["COUNT_FITTING"] > 0){?>
У Вас <?=$arResult["COUNT_FITTING"];?> моделей в корзине
<?}?>

how to make declension:
1 model
2 models
5 models
0 models

Answer the question

In order to leave comments, you need to log in

7 answer(s)
B
Barmunk, 2019-07-16
@Barmunk

$data = [];
foreach($array as $item) {
if ($item['category_id'] == $item['parent_id']) $data[] = $item;
}

but in the example the condition is not met

0
0xD34F, 2019-07-16
@0xD34F

function createTree($data, $idField, $parentField, $rootParent) {
  foreach ($data as $n) {
    $tree[$n[$idField]] = $n;
  }
  foreach ($data as $n) {
    $tree[$n[$parentField]]['children'][] = &$tree[$n[$idField]];
  }

  return $tree[$rootParent]['children'];
}


$tree = createTree($arr, 'category_id', 'parent_id', '');

D
Danil Sapegin, 2017-10-17
@anton99zel

function RusEnding($n, $n1, $n2, $n5) {
    if($n >= 11 and $n <= 19) return $n5;
    $n = $n % 10;
    if($n == 1) return $n1;
    if($n >= 2 and $n <= 4) return $n2;
    return $n5;
  }
echo RusEnding(40, "комментарий", "комментария", "комментариев");

A
Alexey Skobkin, 2017-10-17
@skobkin

This is called pluralization.
You can search implementations for the keyword "plural" on packagist.
Examples:
doctrine/inflector
symfony/inflector
mmucklo/inflect
wapmorgan/morphos (specially for Russian and English).

F
Fuze, 2017-10-18
@InstantMedia

Like this
Use like this:

html_spellcount(54, 'модель|модели|моделей');
// или так
html_spellcount(54, 'модель', 'модели', 'моделей');
// выведет: 54 модели

B
Boris Korobkov, 2017-10-17
@BorisKorobkov

www.yiiframework.com/doc-2.0/guide-tutorial-i18n.h...
php.net/manual/en/intro.intl.php

L
Leonid Smirnov, 2018-10-24
@SunyJun

Here is the answer to your question - https://www.pandoge.com/moduli_i_skripty/prostoe-s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question