通过使用PHP比较两个数组,无法正确显示回显值

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.

The test if (count($maindata) < count($childata)) { is false for your 2 last examples.

I suggest you remove this test.

I think this will be good enough:

$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));


foreach($childata as $key => $value){
    if(in_array($value, $maindata[$key])){
        echo "get the value 
".$childata[$key]['id'];
        echo "delete the value 
".$childata[$key]['id'];
        echo "insert the value 
".$childata[$key]['id'];
    } else {
        echo "delete the value 
".$childata[$key]['id'];
    }
}