Hello,
I want to check difference between 2 arrays
I have two array with key value pair.
I want to check diff between these two. If there is diff then I will insert.
But in some cases, i have extra size in any one of arrays
or both array can be exact same , in which case i will not do anything.
Suppose I have one array as :
Array
(
[0] => Array
(
[gslab_id] => GS-0001
[college_name] => IIT ABC
[degree_name] => B.Tech.
[specialization_in] => Electrical
[univercity] => IIT ABC
[year_of_passing] => 0000-00-00
)
[1] => Array
(
[gslab_id] => GS-0001
[college_name] => NA
[degree_name] => M.S.
[specialization_in] => Electrical
[univercity] => Virginia Tech., USA
[year_of_passing] => 0000-00-00
)
[2] => Array
(
[gslab_id] => GS-0001
[college_name] => NA
[degree_name] => Ph.D.
[specialization_in] => Computer Science
[univercity] => North Carolina State, USA
[year_of_passing] => 0000-00-00
)
)
and onther as :
Array
(
[0] => Array
(
[gslab_id] => GS-0001
[college_name] => IIT ABC
[degree_name] => B.Tech.
[specialization_in] => Electrical
[univercity] => IIT ABC
[year_of_passing] => 1983
)
[1] => Array
(
[gslab_id] => GS-0001
[college_name] => NA
[degree_name] => M.S.
[specialization_in] => Electrical
[univercity] => Virginia Tech., USA
[year_of_passing] => 1985
)
[2] => Array
(
[gslab_id] => GS-0001
[college_name] => NA
[degree_name] => Ph.D.
[specialization_in] => Computer Science
[univercity] => ABCD
[year_of_passing] => 1990
)
[3] => Array
(
[gslab_id] => GS-0001
[college_name] => NA
[degree_name] => M. Phil.
[specialization_in] => Computer Science
[univercity] => North Carolina State, USA
[year_of_passing] => 1995
)
)
In above case I have , I have diff between [2]nd array as well as new array is added at [3]
So how can I check in such situation .
I tried with function [got from stackoverflow ]
public function multi_diff($arr1,$arr2){
$result = array();
foreach ($arr1 as $k=>$v){
if(!isset($arr2[$k])){
$result[$k] = $v;
} else {
if(is_array($v) && is_array($arr2[$k])){
$diff = $this->multi_diff($v, $arr2[$k]);
if(!empty($diff))
$result[$k] = $diff;
}
}
}
return $result;
}
but is is not giving outout.
it return
Array
(
)
Inline Code Example Here
where there is diff even.
I tried with serialization diff, it gives me "there is diff " when there is not.
Totaly clueless now for this conditions.
Can anyone help me?
I was thinking of one solution: make only one array of diff.
But, in case difference between values , I want to update those perticular array . So i could not process of "delete -> and then insert"