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);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.7
array ( 1701 => array ( 'total_space' => 0, 'count' => 0, ), 1702 => array ( 'total_space' => 0, 'count' => 0, ), 1703 => array ( 'total_space' => 20, 'count' => 25.0, ), 1704 => array ( 'total_space' => 28, 'count' => 32.0, ), )

preferences:
85.67 ms | 1302 KiB | 4 Q