- json_decode: documentation ( source)
- print_r: documentation ( source)
- array_merge: documentation ( source)
- json_encode: documentation ( source)
<?php
$old = '{"4":{"deu":1, "eng":1, "fra":1}}';
$new = '{"4":{"deu":1, "eng":2}}';
$oldArray = json_decode($old,true);
$newArray = json_decode($new,true);
$finalArray =[];
foreach($oldArray as $key=>$value){
$finalArray[$key] = array_merge($value,$newArray[$key]);
}
print_r($finalArray);
echo json_encode($finalArray);