问题
I have a multidimensional array like this :
$products Smarty_Variable Object (3)
->value = Array (2)
0 => Array (73)
id_product => "1"
id_supplier => "1"
id_manufacturer => "1"
id_tax_rules_group => "1"
id_category_default => "2"
id_color_default => "2"
on_sale => "0"
online_only => "0"
ean13 => "0"
upc => null
ecotax => "0.000000"
quantity => "50"
minimal_quantity => "1"
price => 189.05
wholesale_price => "70.000000"
unity => null
unit_price_ratio => "0.000000"
additional_shipping_cost => "0.00"
reference => ""
supplier_reference => ""
location => null
width => "0"
height => "0"
depth => "0"
weight => "0.5"
out_of_stock => "2"
quantity_discount => "0"
customizable => "0"
uploadable_files => "0"
text_fields => "0"
active => "1"
available_for_order => "1"
condition => "new"
show_price => "1"
indexed => "1"
cache_is_pack => "0"
cache_has_attachments => "0"
cache_default_attribute => "31"
date_add => "2011-12-02 17:35:57"
date_upd => "2011-12-02 17:35:57"
id_product_attribute => "31"
description => "<p><strong><span style="font-size: sm..."
description_short => "<p>New design. New features. Now in 8..."
available_now => "In stock"
available_later => ""
link_rewrite => "ipod-nano"
meta_description => ""
meta_keywords => ""
meta_title => ""
name => "iPod Nano"
id_image => "1-37"
legend => "iPod Nano"
manufacturer_name => "Apple Computer, Inc"
tax_name => "TVA FR 19.6%"
rate => "19.600"
category_default => "iPods"
new => "1"
orderprice => "149.0000002400000"
attribute => Array (16)
25 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Blue"
id_product_attribute => "25"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "25"
26 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Blue"
id_product_attribute => "26"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "26"
27 => Array (2)
0 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "27"
1 => Array (3)
public_group_name => "Color"
attribute_name => "Yellow"
id_product_attribute => "27"
28 => Array (2)
0 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "28"
1 => Array (3)
public_group_name => "Color"
attribute_name => "Yellow"
id_product_attribute => "28"
29 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Metal"
id_product_attribute => "29"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "29"
30 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Metal"
id_product_attribute => "30"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "30"
32 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Black"
id_product_attribute => "32"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "32"
33 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Orange"
id_product_attribute => "33"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "33"
34 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Orange"
id_product_attribute => "34"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "34"
35 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Pink"
id_product_attribute => "35"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "35"
36 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Pink"
id_product_attribute => "36"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "36"
39 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Green"
id_product_attribute => "39"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "39"
40 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Green"
id_product_attribute => "40"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "40"
41 => Array (2)
0 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "41"
1 => Array (3)
public_group_name => "Color"
attribute_name => "Purple"
id_product_attribute => "41"
42 => Array (2)
0 => Array (3)
public_group_name => "Disk space"
attribute_name => "8Go"
id_product_attribute => "42"
1 => Array (3)
public_group_name => "Color"
attribute_name => "Purple"
id_product_attribute => "42"
31 => Array (2)
0 => Array (3)
public_group_name => "Color"
attribute_name => "Black"
id_product_attribute => "31"
1 => Array (3)
public_group_name => "Disk space"
attribute_name => "16Go"
id_product_attribute => "31"
In my tpl i have this :
{foreach from=$product.attribute key='id_attribute' item='attribute'}
<li>{$attribute}</li>
{/foreach}
This code return me an array.
How can i display all the value like this :
- Color blue , disk space : 16Go (array 25)
- Color blue, disk space : 8Go (array 26)
- ...
I have to make multiple foreach ? thx
回答1:
Yes, you need an inner {foreach}
block.
{foreach from=$product.attribute key='id_attribute' item='attribute'}
<li>
{foreach from=$attribute key='id_property' item='property'}
{$property.public_group_name}
{$property.attribute_name}
{/foreach}
</li>
{/foreach}
来源:https://stackoverflow.com/questions/8401154/smarty-multidimensional-array