I am getting the following error while comparing two array using PHP.
Error:
Notice: Undefined offset: 1 in /opt/lampp/htdocs/test/search.php on line 7
Notice: Undefined offset: 1 in /opt/lampp/htdocs/test/search.php on line 15
delete the valueNotice: Undefined offset: 2 in /opt/lampp/htdocs/test/search.php on line 7
Notice: Undefined offset: 2 in /opt/lampp/htdocs/test/search.php on line 15
delete the value
I am explaining my code below.
$maindata=array(array('id'=>3),array('id'=>7),array('id'=>9));
$childata=array(array('id'=>3),array('id'=>45));
for($i=0;$i<count($maindata);$i++){
//print_r($childata);
if(count($childata) > 0){
if(in_array($childata[$i],$maindata)){
echo "get the value \n".$maindata[$i]['id'];
echo "insert the value \n".$maindata[$i]['id'];
unset($childata[$i]);
if(count($childata) > 0){
$childata=array_values($childata);
}
}else{
echo "delete the value \n".$childata[$i]['id'];
unset($childata[$i]);
if(count($childata) > 0){
$childata=array_values($childata);
}
}
}else{
echo "get the value \n".$maindata[$i]['id'];
echo "insert the value \n".$maindata[$i]['id'];
}
}
Please help me to resolve this error.
$childatavalue is present inside$maindataarray then the twoechowill execute and that particular value will remove.Once$childatalength will be zero then the 2nd else part will excute. - user5443928array_udiff_assocwith a callback or something? - Taha Paksu