Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/15/2023 in all areas

  1. Here's one way $student_scores = [ [ 'name' => 'Student A', 'score' => 68, 'pos' => '' ], [ 'name' => 'Student B', 'score' => 52, 'pos' => '' ], [ 'name' => 'Student C', 'score' => 73, 'pos' => '' ], [ 'name' => 'Student D', 'score' => 80, 'pos' => '' ], [ 'name' => 'Student E', 'score' => 56, 'pos' => '' ], [ 'name' => 'Student F', 'score' => 77, 'pos' => '' ], [ 'name' => 'Student G', 'score' => 73, 'pos' => '' ], [ 'name' => 'Student H', 'score' => 49, 'pos' => '' ], [ 'name' => 'Student I', 'score' => 88, 'pos' => '' ], [ 'name' => 'Student J', 'score' => 90, 'pos' => '' ] ]; $scores = array_column($student_scores, 'score'); rsort($scores); foreach ($student_scores as &$s) { $s['pos'] = array_search($s['score'], $scores) + 1; } // sort scores by position uasort($student_scores, fn($a, $b) => $a['pos']<=> $b['pos']); // show results echo '<pre>' . print_r($student_scores, 1) . '</pre>'; giving Array ( [9] => Array ( [name] => Student J [score] => 90 [pos] => 1 ) [8] => Array ( [name] => Student I [score] => 88 [pos] => 2 ) [3] => Array ( [name] => Student D [score] => 80 [pos] => 3 ) [5] => Array ( [name] => Student F [score] => 77 [pos] => 4 ) [2] => Array ( [name] => Student C [score] => 73 [pos] => 5 ) [6] => Array ( [name] => Student G [score] => 73 [pos] => 5 ) [0] => Array ( [name] => Student A [score] => 68 [pos] => 7 ) [4] => Array ( [name] => Student E [score] => 56 [pos] => 8 ) [1] => Array ( [name] => Student B [score] => 52 [pos] => 9 ) [7] => Array ( [name] => Student H [score] => 49 [pos] => 10 ) )
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.