📜 ⬆️ ⬇️

Declination of nouns with numerals

You, probably, faced a problem when a word with a value of a number, which, for example, is derived directly from the database, needs to be inclined depending on the meaning, but you do not know how. The function below will help you.

<? php
function plural ($ n, $ form1, $ form2, $ form5)
{
$ n = abs ($ n)% 100;
$ n1 = $ n% 10;
if ($ n> 10 && $ n <20) return $ form5;
else if ($ n1> 1 && $ n1 <5) return $ form2;
else if ($ n1 == 1) return $ form1;

return $ form5;
}
$ n = 3; // Value from the database
echo $ n. "" .plural ($ n, "letter", "letters", "letters"). "in your box";
?>

')

Source: https://habr.com/ru/post/11555/


All Articles