I have two objects like this.
$array1
stdClass Object (
[BellId] => 2
[BellCode] => BP001
[BellDescription] => SPI SPEED ABNORMAL,CHK BELT
[ControllerId] => 3
[CreatedBy] => 1
[CreatedOn] => 2016-08-19 15:09:25
[ModifiedBy] =>
[ModifiedOn] =>
)
$array2
stdClass Object (
[BellId] => 1
[BellCode] => BP002
[BellDescription] => MCB TRIPPED,CHK MTR SHORT,O/L.
[ControllerId] => 3
[CreatedBy] => 1
[CreatedOn] => 2016-08-19 15:09:25
[ModifiedBy] =>
[ModifiedOn] =>
)
I need to compare this object and get the difference in these two objects only.
I have checked the below links but no use.
Comparing two stdClass Objects
My Sample code is as follows
function recursive_array_diff($a1, $a2) {
$r = array();
foreach ($a1 as $k => $v) {
if (array_key_exists($k, $a2)) {
if (is_array($v)) {
$rad = recursive_array_diff($v, $a2[$k]);
if (count($rad)) {
$r[$k] = $rad;
}
} else {
if ($v != $a2[$k]) {
$r[$k] = $v;
}
}
} else {
$r[$k] = $v;
}
}
return $r;
}
Can someone help me with the code.