php - 将多个数组合并为一个后接收错误
问题描述
我将一组数组分组在一个数组下$Final_updts[]
,如下所示: 请注意,这些数组在组合之前工作正常。
array(5) {
[0]=> array(0) { }
[1]=> array(0) { }
[2]=> array(3) {
[0]=> object(stdClass)#372 (21) {
["id"]=> int(8) ["created_at"]=> string(19) "2019-11-08 11:07:55"
["updated_at"]=> string(19) "2019-11-08 11:07:55"
["title"]=> string(42) "question 1" ["body"]=> string(47) "Answer 1"}
}
然后我将它返回到视图:
return view('updates', ['f_updt' => $Final_updts]);
看法 :
@if(!empty($f_updt))
@foreach($f_updt as $f_updts)
<div class="post00" >
<p>Other posts</p>
<a href="/sharp/posts/{{ $f_updts->id }}">
<h3> {{$f_updts->title}} </h3>
<br>
<h5> {{$f_updts->body}} </h5>
</a>
</div>
<br>
@endforeach
@endif
我收到此错误:
Trying to get property of non-object
解决方案
@foreach($f_updt as $x => $f_updts)
@foreach($f_updts as $f_updts1)
@if(isset($f_updts1))
@if(isset($f_updts1->id))
<div class="post00">
<p>Other posts</p>
<a href="/sharp/posts/{{ $f_updts1->id }}">
<h3> {{$x}} </h3>
<br>
<h4> {{$f_updts1->title}} </h4>
<br>
<h5> {{$f_updts1->body}} </h5>
</a>
</div>
<br>
@endif
@endif
@endforeach
@endforeach
推荐阅读
- html - Bootstrap 列内容图像响应性
- rpgle - 使用 RPG 和 DSPF 转到文本字符串中的第 n 个字符
- android - 尝试在自定义布局中合并两个布局
- java - 如何使用流获取具有多个属性最大值的对象?
- javascript - 将具有动态键的对象数组转换为新数组
- c++ - 如何对抽象类对象进行排序
- xpath - 如何将几个正则表达式组合成一个?
- java - 存储/缓冲文件以便在 MediaPlayer 中快速访问 - File vs FileInputStream vs FileDescriptor
- android - 为什么我不能在我的颤振项目中添加任何插件?
- sql - MS Access 在我的查询的开关中使用嵌套选择