3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sortedScores = [ ['student_id' => 2, 'total_score' => 443], ['student_id' => 4, 'total_score' => 410], ['student_id' => 1, 'total_score' => 371], ['student_id' => 3, 'total_score' => 170], ]; foreach($sortedScores as $idx => $row) $sortedScores[$idx]['rank'] = $idx+1; var_export($sortedScores);

preferences:
118.41 ms | 404 KiB | 5 Q