How get I get the combined result from two different array i'm using twig template engine
Array:-
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
)
)
What I want
What I tried
<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>
You can use the loop variable.
So : {{item.price[loop.index0]}}
Be careful with two things :
index0
instead of index
or you are going to iterate over your arrayprice
and labels
array must have the same sizeYou can try use loop.index0
to get array index. Documentation here.
Try following code:
<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>