douyou7878 2014-02-26 14:05
浏览 355
已采纳

无法解决这个问题:为foreach()提供的参数无效

I am getting and error Invalid argument supplied for foreach() in the code bellow. Can anyone tell me what I am doing wrong here? I am trying to access the sub array values [0] and [1] here. Just to mention that I have no idea now many values will be in the sub array.

I have placed a comment above of the offending line of code (where the error is)

  echo "<pre>";
  print_r($mySessData);
  echo "</pre>";


Array
(
    [addtypeid] => 
    [isnew] => 
    [orderby] => 
    [geographicareaid] => 
    [catid] => 1
    [catid2] => 
    [manufacturerid] => 
    [modelid] => 
    [yearofmanufacturing_from] => 
    [yearofmanufacturing_to] => 
    [hoursused_from] => 
    [hoursused_to] => 
    [horsepowers_from] => 
    [horsepowers_to] => 
    [price_from] => 
    [price_to] => 
    [colorid] => 
    [isdamaged] => 
    [categoriesfilters] => 
    Array
        (
            [0] => 67
            [1] => 158
        )
)

 $sessData = array();
 $myresult = array();
 $val = array();   

 if (!empty($mySessData)){
     foreach ($mySessData as $sessData) { 
         // the line bellow is the offending line, where the error is thrown
         foreach ($sessData as $val) { 
             $myresult[$val]= $val; 

             foreach($filters as $f) {
                 if ($f['filterid'] == $myresult[$val]) {
                     $strWhere2 .= $myresult[$val] .",";
                 } // end if
             } // end of third foreach

         } // end of second foreach 
     } // end of first foreach
 } // end if
  • 写回答

4条回答 默认 最新

  • dongsan6889 2014-02-26 14:08
    关注

    That is because you aren't checking if $sessData is actually an array. In fact, it's an array in only one case looking at your dump. Just add another if (is_array($sessData))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?