I need to display some echo
value by comparing two array using PHP. 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),array('id'=>7),array('id'=>123));
for($i=0;$i < count($childata);$i++){
if(in_array($childata[$i],$maindata)){
echo "get the value
".$maindata[$i]['id'];
echo "delete the value
".$maindata[$i]['id'];
echo "insert the value
".$maindata[$i]['id'];
}
if(!in_array($childata[$i],$maindata)){
echo "delete the value
".$childata[$i]['id'];
}
}
Here my requirement is if any data from first array($maindata
) is present in second array(i.e-$childata
) then the first three echo message
will display and other value from second array(i.e-$childata
) the second only one echo message
will display. But in some cases it is not working like below.
Cases:
$maindata=array(array('id'=>3),array('id'=>7),array('id'=>9));
$childata=array(array('id'=>3),array('id'=>45),array('id'=>123));
or
$maindata=array(array('id'=>3),array('id'=>7),array('id'=>9));
$childata=array(array('id'=>3),array('id'=>45));
The first case from above I need for all value from $maindata
array the first three echo message
will display and for array('id'=>45) and array('id'=>123)
the only last one echo message
will display. Similarly for the second case from above all value from $maindata
array the first three echo message
will display and for array('id'=>45)
the only last one echo message
will display.