How to make a conclusion of the end, if 1 user, then writes "1 user", if 2, 3, 4, then "user", if 6, then "user".

Below is the code that needs to be edited.

<?php $user_count = user_count(); $suffix = ($user_count !=1) ? 'ей' : 'ь'; ?> у нас <?php echo $user_count; ?> пользовател<?php echo $suffix; ?> зарегистрировано 

    3 answers 3

     $users = array('Пользователей','Пользователь','Пользователя'); // 0,1,2 if( $user_count%100 >= 5 && $user_count%100 < 21) $form = 0; else if( $user_count % 10 == 1) $form = 1; else if( in_array( $user_count % 10, array(2,3,4), TRUE)) $form = 2; else $form = 0; printf( '<p>У нас %d %s</p>', $user_count, $users[$form]); 
    • one
      check your algorithm for the numbers 111..114 - xEdelweiss
    • Oh thank you earned) - LLIAKAJI
    • @xEdelweiss, thanks, I was too lazy to check. Repaired - Sergiks

    To edit it, try it yourself, but here 's a hint how this is done.

    User: (n mod 10 = 1) AND (n mod 100 != 11)
    User: (n mod 10 = 2..4) AND (n mod 100 != 12..14)
    To her : (n mod 10 = 0) OR (n mod 10 = 5..9) OR (n mod 100 = 11..14)
    User: остальное

      can be used

        `switch{ case variant_1: echo"++++++"; break; case variant_2: echo"+-+-+"; break; }`