如何从两个不同的数组中获得组合结果我正在使用twig模板引擎
阵列: -
Array
(
[0] => Array
(
[id] => 1
[title] => This is title
[labels] => Array
(
[0] => This is label-1
[1] => This is lable-2
)
[price] => Array
(
[0] => 50
[1] => 90
)
[desc] => great item
[tags] => item,great
[time] => 1352129710
)
)
我想要什么
我尝试了什么
<ul>
{% for item in market %}
<li>{{ item.title }}</li>
<ul>
{% for key in item.labels %}
<li>{{ key }} - **HOW TO DISPLAY PRICE HERE FROM [price]=>Array(..) **</li>
{% endfor %}
</ul>
{% endfor %}
</ul>
答案 0 :(得分:1)
您可以尝试使用loop.index0
来获取数组索引。文档here。
请尝试以下代码:
<ul>
{% for item in market %}
<li>{{ item.title }}</li>
<ul>
{% for key in item.labels %}
<li>{{ key }} - {{ item.price[loop.index0] }}</li>
{% endfor %}
</ul>
{% endfor %}
</ul>
答案 1 :(得分:1)