Example 1 — Sort Scores Low to High
Order players from the lowest score to the highest.
<?php
$scores = ["Ann" => 80, "Ben" => 95, "Cara" => 70];
asort($scores);
foreach ($scores as $name => $score) {
echo $name, ": ", $score, PHP_EOL;
} How It Works
- The array stores a score for each name.
- asort() puts the values in ascending order.
- Each name moves together with its own score.
- The loop prints from the lowest score to the highest.

