PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > 编程杂谈 > 正文

    出现Warning: Illegal string offset的解决方法

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:今天在做ecshop的时候,一段代码出现Warning: Illegal string offset的这样的错误,代码如下$catlist = array_merge(cat_list(0, 0,...
    今天在做ecshop的时候,一段代码出现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)),这样就搞定了。
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-74-2008-1.html
    相关热词搜索: