Skip to content

Instantly share code, notes, and snippets.

@Nex-Otaku
Created September 7, 2018 08:30
Show Gist options
  • Save Nex-Otaku/a08ecf9e10d17cd6b381ed93bab03504 to your computer and use it in GitHub Desktop.
Save Nex-Otaku/a08ecf9e10d17cd6b381ed93bab03504 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: programmer
* Date: 09.11.2015
* Time: 15:10
*/
namespace common\helpers;
class numericals
{
public static function numericals($str, $num){
$strEnd = '';
$ost10 = fmod($num, 10);
$ost100 = fmod($num, 100);
$endingOne = '';
$endingOneFour = 'а';
$endingMany = 'ов';
if($str == 'заняти') {
$endingOne = 'е';
$endingOneFour = 'я';
$endingMany = 'й';
}
if ($ost10 == 1 && $ost100 != 11) {
$strEnd = $endingOne;
} elseif((($ost10 > 1 && $ost10 < 5) || ($ost10>0 && $ost10<1)) && ($ost100<10 || $ost100>20)){
$strEnd = $endingOneFour;
} elseif(($ost10 == 0) || ($ost10 >= 5 && $ost10 <= 9) || ($ost100 >= 11 && $ost100 <= 19)){
$strEnd = $endingMany;
}
return $str . $strEnd;
}
/**
* @param $ends array of
* [
* {(str) for where (the latter figure of $num) = 1, exclude 11},
* {(str) for where 1 < (the latter figure of $num) < 5 && 10 > (the last two digits of $num) > 20}
* {(str) for where (the latter figure of $num) = 0 || 5 <= (the latter figure of $num) <= 9 || 11 <= (the last two digits of $num) > 19}
* ]
* @param $num
* @return string
*/
public static function numericalsByArray($ends, $num){
$strEnd = '';
$ost10 = fmod($num, 10);
$ost100 = fmod($num, 100);
if($ost10 == 1 && $ost100 != 11){
$strEnd = $ends[0];
}
elseif(($ost10 > 1 && $ost10 < 5) && ($ost100<10 || $ost100>20)){
$strEnd = $ends[1];
}
elseif(
( $ost10 == 0 )
|| ( $ost10 >= 5 && $ost10 <= 9 )
|| ( $ost100 >= 11 && $ost100 <= 19 )
){
$strEnd = $ends[2];
}
return $strEnd;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment