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
网友评论