3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data_json = '{ "EXPORT": [ { "dates": "2019-07-01", "c_job": 12 }, { "dates": "2019-07-02", "c_job": 8 }, { "dates": "2019-07-04", "c_job": 11 } ], "IMPORT": [ { "dates": "2019-07-03", "c_job": 11 } ] }'; $blank_json = '[ { "dates": "2019-07-01", "c_job": 0 }, { "dates": "2019-07-02", "c_job": 0 }, { "dates": "2019-07-03", "c_job": 0 }, { "dates": "2019-07-04", "c_job": 0 } ]'; $data = json_decode($data_json, true); $blank = json_decode($blank_json, true); $datafinal = array(); foreach ($data as $key => $value) { foreach ($blank as $bkey => $bvalue) { if (($dkey = array_search($bvalue['dates'], array_column($value, 'dates'))) !== false) { $datafinal[$key][$bkey] = $value[$dkey]; } else { $datafinal[$key][$bkey] = $bvalue; } } } echo json_encode($datafinal, JSON_PRETTY_PRINT);

preferences:
119.51 ms | 407 KiB | 5 Q