Array $imagelist:
Array (
[additional] => Array (
[count] => 2
[image] => Array (
[nokia_e61_1.jpg] => Array (
[name_body] => nokia_e61_1
[name_ext] => jpg
)
[nokia_e61_2.jpg] => Array (
[name_body] => nokia_e61_2
[name_ext] => jpg
)
[nokia_e61_3.jpg] => Array (
[name_body] => nokia_e61_3
[name_ext] => jpg
)
[nokia_e61_4.jpg] => Array (
[name_body] => nokia_e61_4
[name_ext] => jpg
)
)
)
[main] => nokia_e61
)
值nokia_e61_1.jpg
保存在{$getvars.imagename}
。
我写了{$imagelist.additional.image.`$getvars.imagename`.name_body}
但它不起作用。
请帮忙。
答案 0 :(得分:22)
查看{$imagelist.additional.image[$getvars.imagename].name_body}
是否有效
答案 1 :(得分:4)
我不喜欢这个,但我使用它。 这是摘录表单文档
{$foo.$bar} <-- display variable key value of an array, similar to PHP $foo[$bar]
为了能够做到这一点,你必须
{assign var='key' value=$getvars.imagename}
{$imagelist.additional.image.$key.name_body}
希望有所帮助
答案 2 :(得分:3)
重组数组,内部“图像”偏移的键无论如何都是多余的:
$imagelist = array('additional' => array('count' => 2,
'image' => array(
array('name_body' => 'nokia_e61_1',
'name_ext' => 'jpg'),
array('name_body' => 'nokia_e61_2',
'name_ext' => 'jpg'),
array('name_body' => 'nokia_e61_3',
'name_ext' => 'jpg'),
array('name_body' => 'nokia_e61_4',
'name_ext' => 'jpg')
)
),
'main' => 'nokia_e61'
);
为您提供数字索引图像:
array(2) {
["additional"]=>
array(2) {
["count"]=>
int(2)
["image"]=>
array(4) {
[0]=>
array(2) {
["name_body"]=>
string(11) "nokia_e61_1"
["name_ext"]=>
string(3) "jpg"
}
[1]=>
array(2) {
["name_body"]=>
string(11) "nokia_e61_2"
["name_ext"]=>
string(3) "jpg"
}
[2]=>
array(2) {
["name_body"]=>
string(11) "nokia_e61_3"
["name_ext"]=>
string(3) "jpg"
}
[3]=>
array(2) {
["name_body"]=>
string(11) "nokia_e61_4"
["name_ext"]=>
string(3) "jpg"
}
}
}
["main"]=>
string(9) "nokia_e61"
}
//and then the smarty bit
{$imagelist.additional.image[0].name_body}
{$imagelist.additional.image[1].name_body}
{$imagelist.additional.image[2].name_body}
{$imagelist.additional.image[3].name_body}
答案 3 :(得分:0)
{php}echo $imagelist['additional']['image'][$getvars['imagename']]['name_body'];{/php}