Advertisement
vitvayti

Склонение

Oct 8th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function num2word($num, $words)
  2. {
  3. $num = $num % 100;
  4. if ($num > 19) {
  5. $num = $num % 10;
  6. }
  7. switch ($num) {
  8. case 1: {
  9. return ($words[0]);
  10. }
  11. case 2:
  12. case 3:
  13. case 4: {
  14. return ($words[1]);
  15. }
  16. default: {
  17. return ($words[2]);
  18. }
  19. }
  20. }
  21.  
  22. // example
  23.  
  24. $words = array("отзыв", "отзывов", "отзыва");
  25. $num = 10;
  26.  
  27. echo "Осталось ".num2word($num, $words);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement