Last active
April 26, 2022 07:46
-
-
Save aclips/1ca4a0dc27392ad42119c2d1875a2863 to your computer and use it in GitHub Desktop.
Склонение существительных после числительных
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Склонение существительных после числительных. | |
* | |
* @param string $value Значение | |
* @param array $words Массив вариантов, например: array('товар', 'товара', 'товаров') | |
* @param bool $show Включает значение $value в результирующею строку | |
* @return string | |
*/ | |
public function num_word($value, $words, $show = true) | |
{ | |
$num = $value % 100; | |
if ($num > 19) { | |
$num = $num % 10; | |
} | |
$out = ($show) ? $value . ' ' : ''; | |
switch ($num) { | |
case 1: | |
$out .= $words[0]; | |
break; | |
case 2: | |
case 3: | |
case 4: | |
$out .= $words[1]; | |
break; | |
default: | |
$out .= $words[2]; | |
break; | |
} | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment