PHP在if之后丢失foreach的值


PHP Lost value of foreach after if

如果之后,我在foreach中丢失了值

foreach ($etc_uloziste as  $id => $etc_id) {
    foreach ($etc_id as  $id2 => $etc_id2) {
        if($rodic1==$id) {
            if( ! in_array( $etc_id2, $etc_mn) ) { 
                //Check if the season already is displayed
                $sql.= ",'n"." ".$etc_id2."_id"." INT";
                $etc_mn[] = $etc_id2; //Store the season in the array
            }
        }
    }
}

之前,如果我有这样的值:

[book] => Array
        (
            [0] => library
            [1] => room
        )

但如果之后只有

[book] => Array
        (
            [0] => library
        )

$etc_id2类似于图书馆或房间,$id是图书

我在2中丢失了值。回波

 foreach ($result2 as  $rodic1 => $rodic_hodnot1)
            {           
             foreach ($etc_uloziste as  $id => $etc_id)
                    {                           
                                    foreach ($etc_id as  $id2 => $etc_id2)
                                     {                                  
                                        //echo $etc_id2."'n";                                
                                        if($rodic1 ==$id)
                                           {
                                             //echo $etc_id2."'n";                                              
                                            }                               
                                    }                                                                                                                                                                   
                    }
            }