2013-01-18 94 views
1

我想從數組多維數據庫中循環。這是我製作的示例數組:帶條件的循環索引樹枝

array[0]['name_product'] = 'big cola'; 
array[0]['size'] = '4'; 
array[1]['name_product'] = 'cfc'; 
array[1]['size'] = '1'; 
array[2]['name_product'] = 'hot dog'; 
array[2]['size'] = '1'; 
array[3]['name_product'] = 'pizza'; 
array[3]['size'] = '6'; 

我想循環使用2條件,這是大小=='1'和大小>'1'。之後我想從每一個條件,例如建立循環:

大小== '1',所以:

no  name_product  size 
1  big cola   4 
2  pizza    6 

大小> '1':

no  name_product  size 
1  cfc    1 
2  hot dog   1 

怎麼樣使「不「是增加數組和條件在樹枝? 我希望你能幫助我。謝謝你..

回答

1

你的問題有點不清楚,我假設你正在尋找條件循環。 Twig對此有內置支持,here's the documentation。它被添加到樹枝1.2。

在你的情況,你會做兩個循環(對於兩個表)是這樣的:

{% for product in products if product.size == 1 %} 
    {# your first table #} 
{% endfor %} 

{% for product in products if product.size > 1 %} 
    {# your second table #} 
{% endfor %}