出现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"];
   }

上面代码可以输出值,但是报错Warning: Illegal string offset 'cat_name' in ,原因是$catlist数组里面有空数组,空数组里没有cat_name这个字段。最终解决办法是在 foreach 下面加个判断 if(is_array($val)),这样就搞定了。
 
posted @ 2020-01-11 09:16  李若盛开  阅读(15227)  评论(0)    收藏  举报