use*_*410 1 multidimensional-array phalcon volt
好的,我创建了一个多维数组并将其存储在文章中
如果我做
{{ dump(articles) }}
Run Code Online (Sandbox Code Playgroud)
它返回
array(2) {
["Comedy"]=>
array(3) {
[0]=>
string(18) "Comedy Title1"
[1]=>
string(57) "Comedy Title2"
[2]=>
string(41) "Comedy Title3"
}
["Horror"]=>
array(3) {
[0]=>
string(18) "Horror Title1"
[1]=>
string(57) "Horror Title2"
[2]=>
string(41) "Horror Title3"
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想要实现的是循环,打印标题,然后打印每个部分的标题:
**Comedy**
Comedy Title1
Comedy Title2
Comedy Title3
**Horror**
Horror Title1
Horror Title2
Horror Title3
Run Code Online (Sandbox Code Playgroud)
但是我可以毫无问题地访问标题,但似乎无法访问标题。
这是我到目前为止所拥有的
{% for heading in articles %}
{{ heading[loop.index0] }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
这将返回第一个部分的第一个值和第二个部分的第二个值
comedy Title1
horror Title2
Run Code Online (Sandbox Code Playgroud)
如果我做
{% for heading in articles %}
{% for title in heading %}
{{ title }}<br />
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
这将按正确的顺序返回所有标题,但没有标题,因此:
Comedy Title1
Comedy Title2
Comedy Title3
Horror Title1
Horror Title2
Horror Title3
Run Code Online (Sandbox Code Playgroud)
所以这很完美,但我只需要打印出每个数组开头的标题,这就是我无法弄清楚的
我本以为它存储在标题部分,但 {{ header }} 返回一个数组,而 {{ header[0] }} 返回第一个标题。{{articles}} 返回一个数组,而 {{articles[0] }} 甚至 {{articles[0][0] }} 不返回任何内容
我知道如何在常规 php 中执行此操作,但是我无法弄清楚伏特,毫无疑问是简单的事情
我不熟悉 Volt,但根据文档尝试使用类似的东西:
{% for key, heading in articles %}
** {{ key }} **<br />
{% for title in heading %}
{{ title }}<br />
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1619 次 |
| 最近记录: |