ectouch Warning: Illegal string offset

出现Warning: Illegal string offset的这样的错误,代码如下

$catlist = array_merge(cat_list(0, 0, false), array(‘-‘), article_cat_list(0, 0, false));
foreach($catlist as $key => $val)
{

echo $val[“cat_name”];

}

 

原因是$catlist数组里面有空数组,空数组里没有cat_name这个字段。最终解决办法是在 foreach 下面加个判断 if(is_array($val)),这样就搞定了

发表评论