我有一个看起来像这样的数组:
array:3 [▼
0 => {#354 ▼
+"id": 38
+"block_newsletter_id": 102
+"item_type": "title"
+"html_key": ""
+"content": "TITLE"
+"properties": ""
}
1 => {#355 ▼
+"id": 39
+"block_newsletter_id": 102
+"item_type": "text"
+"html_key": ""
+"content": "Some text. Hey."
+"properties": ""
}
2 => {#356 ▼
+"id": 40
+"block_newsletter_id": 102
+"item_type": "button"
+"html_key": ""
+"content": "click here"
+"properties": ""
}
]
现在我将此数组发送到我的视图,我的目标是在我的 h1 标签中显示 item_type“title”的内容。
我可以这样做:
@foreach($blockItemsContent as $blockItemContent)
@if($blockItemContent->item_type == 'title')
<h1>{{ $blockItemContent->content }}</h1>
@endif
@endforeach
但是如果我想将 item_type 文本放在 ap 标签中,我也需要这样做。没有比必须为每个循环编写多个更有效的方法吗?
元芳怎么了
慕后森
子衿沉夜