F
F
felony13twelve2020-05-12 22:08:39
PHP
felony13twelve, 2020-05-12 22:08:39

How to make statistics?

There is this code

$arr = array('gg' => 22, 'g2' => 0, 'g3' => 233, 'dfd' => 2); 
arsort($arr); 
$place = 1; 
foreach ($arr as $key => $val) { 
 echo "{$place} - {$key}: {$val}<br>"; 
 $place++; 
}

These are my statistics (do not judge strictly, purely a test), but it displays all 4 places, but it needs to display only three places, if we say I have only one user in the array, then it needs to display 1 place. If there are 5 users in the array, then it is necessary that it also displays only three places, Mysql do not advise, I need it in an array without a database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
4
4sadly, 2020-05-13
@felony13twelve

$arr = array('gg' => 22, 'g2' => 0, 'g3' => 233, 'dfd' => 2); 
arsort($arr); 
$place = 1; 
foreach ($arr as $key => $val) { 
 if($place>3) break;
 echo "{$place} - {$key}: {$val}<br>"; 
 $place++; 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question