You have two arrays containing objects -- using array_udiff()
is certainly appropriate for this task.
I'll demonstrate this technique with modern syntax ("spaceship operator" and "arrow function syntax").
Consider this sample dataset:
$array1 = [
(object) ['id' => '204', 'day_id' => '12'],
(object) ['id' => '205', 'day_id' => '13'],
(object) ['id' => '206', 'day_id' => '14'],
(object) ['id' => '207', 'day_id' => '15'],
];
$array2 = [
(object) ['id' => '203', 'day_id' => '11'],
(object) ['id' => '205', 'day_id' => '13'],
(object) ['id' => '207', 'day_id' => '14'],
(object) ['id' => '209', 'day_id' => '17'],
];
The returned data from array_udiff()
will be the rows from the first array that are not matched in the second array.
Code: (Demo)
var_export(
array_udiff(
$array1,
$array2,
fn($a, $b) => $a->id <=> $b->id
)
);
returns these two rows:
[
(object) ['id' => '204', 'day_id' => '12'],
(object) ['id' => '206', 'day_id' => '14'],
]
Reversing the order of the first two parameters: (Demo)
[
(object) ['id' => '203', 'day_id' => '11'],
(object) ['id' => '209', 'day_id' => '17'],
)