After you decode the JSON:
$data = json_decode($json, true);
You can use array_diff to remove the values in fav
that are also in scheduled
.
$fav = array_values(array_diff(
array_column($data['fav'], 'id'),
array_column($data['scheduled'], 'id')));
(The array_values
is necessary because array_diff
will preserve the keys, and you'll need sequential zero-indexed keys for reencoding to JSON to work properly.)
Then map those values back to the {id: value}
format and reassign the result to $data['fav']
.
$data['fav'] = array_map(function($item){ return ['id' => $item]; }, $fav);
Then, obviously, reencode as JSON.
$json = json_encode($data);