【发布时间】:2021-03-26 20:55:03
【问题描述】:
大多数语言都允许您循环遍历 json 对象,获取顶级名称。
object = {
"a": {"inner json objects"},
"b" : {"..."},
"C" : {"..."}
}
例如在 html.twig 中的语法是这样的:
{% for title, section in object %}
// do something with title (ie. a, b, c)
// do something (cycle through) with section(ie. '...')
{% endfor %}
我想在blade.php中做同样的事情。
我尝试了刀片语法的多种变体,例如
@foreach(json_encode($object) as $title)
但我想不通,我在网上找不到任何合适的文档。 This stackoverflow question is the closest I could find.,但这不太合适,因为它没有规定我要从中抓取的对象
任何帮助将不胜感激。
【问题讨论】:
-
“功能”是什么意思?元素、属性?
-
您好,为了更清楚,我已经编辑了这个问题。谢谢
-
foreach ($thing as $key => $value)?以及为什么要调用json_encode将某些内容变成字符串... PHP 手册是您的朋友 -
是的!谢谢,那行得通。 @foreach($theme as $title => $section)
-
在那里写下它作为答案,如果你愿意,我会接受/投票。干杯
标签: php laravel laravel-blade