我从控制器那里得到了以下信息:
{ “CAT_ID”:17, “课程”: “数学”, “subcat_info”:[{ “subcat_id”:43,的 “标题”: “测试”, “CAT_ID”:17}]}
现在我想从subcat_info获取(title:test)的标题。
我尝试在刀片视图中关注foreach(结果为空白)
@foreach($ cats as $ cat) {{$ cat-> subcat_info [0] - > title}} @end
如何从中获得头衔?
答案 0 :(得分:0)
试试这个
$json = '{
"cat_id":17,
"course":"Maths",
"subcat_info":[{
"subcat_id":43,
"title":"Test",
"cat_id":17
}]
}';
$array = json_decode($json,true);
echo $array['subcat_info'][0]['title'];
<强>输出强>
测试
答案 1 :(得分:0)
@foreach($cats as $cat)
{{ $cat->course }} // if you like to print the "title" of the category
@foreach($cat->subcat_info as $subcat)
{{ $subcat->title }}
@endforeach
@endforeach