Skip to content

Instantly share code, notes, and snippets.

@Mausglov
Created September 23, 2015 16:25
Show Gist options
  • Save Mausglov/8d66e6ed67589c80fe90 to your computer and use it in GitHub Desktop.
Save Mausglov/8d66e6ed67589c80fe90 to your computer and use it in GitHub Desktop.
функция склонения имени ( "1 мешок", "2 мешка", "5 мешков"
<?
/**
* @param float $total
* @param string $one
* @param string $two
* @param string $five
* @return string
*/
function strEnd($total, $one, $two, $five) {
if($total > floor($total)) return $two;
$v = intval( abs($total) ) % 100;
if ( $v > 19 ) {
$v = $v % 10;
}
if ( $v == 1 ) {
return $one;
}
if ( $v > 1 && $v < 5 ) {
return $two;
}
return $five;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment