3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{"description 1": { "year0": "49", "year1": "48", "year2": "876786", "year3": "1234" } }'; $a = json_decode($json, true); $r = []; foreach($a['description 1'] as $k => $v){ $index = (int) filter_var($k, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $r[$k] = ($index == 0) ? '' : $a['description 1']['year'.--$index]; } print_r($r);
Output for 7.1.25 - 7.1.32, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Array ( [year0] => [year1] => 49 [year2] => 48 [year3] => 876786 )

preferences:
141.93 ms | 408 KiB | 5 Q