V
V
Valera Dobroman2020-04-30 05:39:58
PHP
Valera Dobroman, 2020-04-30 05:39:58

How do you know what's at the end of a number?

I have a string or a number, I need to find out what is at the end of this number in order to determine how many views
. For example, how to do this?
If 1 then: 1 view.
If 2 then: 2 viewsA.
If 6 then 6 views.
If 41 then: 41 views.
If 42 then: 42 viewsA.
If 45 then: 45 views.
Etc.
It would be great if you could also tell me how to do this in PHP and JS

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanMogilev, 2020-04-30
@Valera221

PHP

<?php
function RusEnding($n, $n1, $n2, $n5) {
    if($n >= 11 and $n <= 19) return $n5;
    $n = $n % 10;
    if($n == 1) return $n1;
    if($n >= 2 and $n <= 4) return $n2;
    return $n5;
  }
echo RusEnding(1015, "Просмотр", "Просмотра", "Просмотров");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question