PHP如果丢失了foreach的值

时间:2014-04-14 10:56:54

标签: php arrays if-statement foreach

如果

,我在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是书

1 个答案:

答案 0 :(得分:0)

我在2. echo

中丢失了值
 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";                                              
                                            }                               
                                    }                                                                                                                                                                   
                    }
            }