3v4l.org

run code in 500+ PHP versions simultaneously
<?php $tsp = 9; $fin = [ "1701" => ["total_space" => 0, "count" => 0], "1702" => ["total_space" => 0, "count" => 0], "1703" => ["total_space" => 20, "count" => 20], "1704" => ["total_space" => 28, "count" => 28] ]; $qualifiers = array_filter($fin, fn($row) => $row['count']); $divideBy = count($qualifiers); foreach ($qualifiers as $id => $row) { $tsp -= $toAdd = ceil($tsp / $divideBy); --$divideBy; $fin[$id]['count'] += $toAdd; } var_export($fin);

preferences:
26.94 ms | 1304 KiB | 5 Q