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);

preferences:
136.35 ms | 406 KiB | 5 Q