【发布时间】:2012-10-07 15:46:08
【问题描述】:
我在 smarty 中关注数组类型..
[Main_array] => Array
(
[splitlist] => 1
[counter] => 2
[listNames] => Array
(
[0] => Material
[1] => Color
)
[splittedLists] => Array
(
[Material_item_1] => Array
(
[White] => Array
(
[image] => /img/thumbnail.gif
[imageLink] => /static/white.html
)
[Black] => Array
(
[image] => /img/no-image.gif
[imageLink] => /static/black.html
)
)
[Material_item_2] => Array
(
[Red] => Array
(
[image] => /img/no-image.gif
[imageLink] => /static/Red.html
)
[Yellow] => Array
(
[image] => /img/no-image.gif
[imageLink] => /static/yellow.html
)
)
)
)
我想关注这个数组的输出
* Material
- Material_item_1
- Material_item_2
* Color
- Nude
- Black
- Red
- Yellow
到目前为止我所做的如下..
[{foreach from=$item2.listNames key=subKey1 item=subItem1 name=subLp1}]
<h2>
<label>[{$subItem1|replace:"-":" "}]</label>
</h2>
<ul style="margin-left:20px;display:block;">
[{foreach from=$item2.splittedLists key=subKey2 item=subItem2 name=subLp2}]
<li style="float:none;"><strong>[{$subKey2|replace:"-":" "}]</strong></li>
[{/foreach}]
</ul>
[{/foreach}]
我得到了....
* Material
- Material_item_1
- Material_item_1
- Material_item_2
- Material_item_2
* Color
- Material_item_1
- Material_item_1
- Material_item_2
- Material_item_2
我正在使用 PHP - OXID 和 Smarty。在这里我要提到的一件事是[splittedLists] 的元素可能大于或小于 2。但也欢迎使用 2 元素的逻辑。
更新:我已经和客户谈过了,所以现在也欢迎任何关于结构变化的建议。请帮忙
UPDATE2:下面是 PHP 数组。
$arr = array(
'Main_array' => array
(
'splitlist' => 1,
'counter' => 2,
'listNames' => array
(
'0' => "Material",
'1' => "Color"
),
'splittedLists' => array
(
'Material_item_1' => array
(
'White' => array
(
'image' => "/img/thumbnail.gif",
'imageLink' => "/static/white.html"
),
'Black' => array
(
'image' => "/img/no-image.gif",
'imageLink' => "/static/black.html"
)
),
'Material_item_2' => array
(
'Red' => array
(
'image' => "/img/no-image.gif",
'imageLink' => "/static/Red.html"
),
'Yellow' => array
(
'image' => "/img/no-image.gif",
'imageLink' => "/static/yellow.html"
)
)
)
)
);
【问题讨论】:
-
你能显示数组,而不是 var_dump 吗?
-
@Sibu 这个数组我放在这里使用
print_r函数,我觉得够了。 -
我想执行你的代码,所以如果可以提供数组..也许我会尝试
-
我想要完整的数组输出.. 以便我可以提供帮助:)
-
@Sibu & Vijay: PHP 数组已添加到... 希望这对回答我的问题有用.. 谢谢好友..
标签: php multidimensional-array foreach smarty