Skip to content

Instantly share code, notes, and snippets.

@romanoffs
Forked from Neolot/gist:3964380
Created August 11, 2018 19:04
Show Gist options
  • Save romanoffs/76414c57530338f83468e7e4d5b2e7a3 to your computer and use it in GitHub Desktop.
Save romanoffs/76414c57530338f83468e7e4d5b2e7a3 to your computer and use it in GitHub Desktop.
PHP Склонение числительных
<?php
/**
* Функция склонения числительных в русском языке
*
* @param int $number Число которое нужно просклонять
* @param array $titles Массив слов для склонения
* @return string
**/
$titles = array('котик', 'котика', 'котиков');
function declOfNum($number, $titles)
{
$cases = array (2, 0, 1, 1, 1, 2);
return $number." ".$titles[ ($number%100 > 4 && $number %100 < 20) ? 2 : $cases[min($number%10, 5)] ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment