Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Dmitriy Lanets
Added: Jul 7, 2015 6:41 AM
Modified: Oct 15, 2018 12:53 PM
Views: 28
Tags: no tags
  1.    function numberEnd($number, $titles) {
  2.         $cases = array (2, 0, 1, 1, 1, 2);
  3.         return $titles[ ($number%100>4 && $number%100<20)? 2 : $cases[min($number%10, 5)] ];
  4.     }
  5. //1,2,5 склонение в трех вариантах
  6. echo numberEnd(1,["товар","товара","товаров"]);