Recently, I encountered some problem on comparing 2 nested arrays. I have tested to use array_diff_assoc to compare 2 arrays but it return me incorrect. Below are couple scenarios that I am attempt to compare these 2 nested array in php.
$arr1 = ["colorFamily"=>[]];
$arr2 = ["colorFamily"=>["blue","black"]];
$diff = array_diff_assoc($arr1,$arr2);
The $diff is expected to return below;
["colorFamily"=>[]]
Unfortunately, it return below:
[]
Aside from that, there are more complex scenario will be used in the comparison such as
$arr1 = ["colorFamily"=>[],"descriptionMeasurement"=>[["label"=>"orange"],["value"=>"apple"]]];
$arr2 = ["colorFamily"=>["blue","black"],"descriptionMeasurement"=>[["label"=>"orange"]]];
Above scenario, it should return
["colorFamily"=>[],"descriptionMeasurement"=>[["label"=>"orange"]]].
In short, anything occurs in $arr1 and it is not occurs in $arr2, should return in the $diff array. I hope you guys can help me to resolve this problem, I have been stucking for weeks.