- json_decode: documentation ( source)
- filter_var: documentation ( source)
- print_r: documentation ( source)
<?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);