【问题标题】:PHP Lost value of foreach after ifPHP在if之后丢失了foreach的值
【发布时间】:2014-04-14 10:56:54
【问题描述】:

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
        )

但if之后只有

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

$etc_id2 就像图书馆或房间,$id 是书

【问题讨论】:

  • 你能不能 var_dump $etc_uloziste 变量让我们看看它的结构?我感觉你循环的方式不对。
  • 这是我的 $etc_ulozis pastebin.com/zhZKsP1B
  • 你想做什么?
  • ` if($rodic1==$id) ` 如果外部索引超过子数组计数,则将删除除一个数组项之外的所有项或全部
  • if($rodic1==$id ia all tr​​ue 那么我怎样才能得到下一个 [1] => 房间)

标签: php arrays if-statement foreach


【解决方案1】:

我在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";                                              
                                            }                               
                                    }                                                                                                                                                                   
                    }
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    相关资源
    最近更新 更多