美文网首页
laravel 遍历对象并向其插入数据

laravel 遍历对象并向其插入数据

作者: 小李不是你 | 来源:发表于2018-11-28 10:20 被阅读0次

laravel 遍历对象并向其插入数据

1. Indirect modification of overloaded element of XXX has no effect的解决办法
    foreach ($result as $key => $val){
        $attach_id = explode(',',$val->image_id);
        $attachment_list = AttachmentModel::where('id',$attach_id)->get();

        $temp = [];

        foreach ($attachment_list as $k => $v){
            $temp[$k] = isset($v['image_url'])?$v['image_url']:'';
        }
        $result[$key]['img_url'] = $temp;
        unset($temp,$attachment_list);
    }
    
    注意:利用中间变量 $temp  来解决遍历对象时报错问题
    
    报错:Indirect modification of overloaded element of XXX has no effect

相关文章

网友评论

      本文标题:laravel 遍历对象并向其插入数据

      本文链接:https://www.haomeiwen.com/subject/mqqaqqtx.html