smarty的多维数组循环判断并输出问题

#1 prince

  如题,实在搞不定了,先是一个一维数组(顶级的分类):topcat(id,name这两个元素)
下边是顶级分类下边的分类(Scat),如下所取得的数组:
Array
(
        [0] => Array(
                            [id] => 2
                            [name] => 软件服务
                            [indexSub] => 3
                            [services] => Array(
                                                          [0] => Array(
                                                                               [id] => 1
                                                                               [name] => 金蝶软件维护
                                                                               [catid] => 2
                                                                              )

                    [1] => Array
                        (
                            [id] => 2
                            [name] => windows系统维护
                            [catid] => 2
                        )

                )

        )

    [1] => Array
        (
            [id] => 3
            [name] => 硬件服务
            [indexSub] => 3
            [services] => Array
                (
                )
)
[2] => Array
        (
            [id] => 4
            [name] => 网络服务
            [indexSub] => 3
            [services] => Array
                (
                )
)
  [3] => Array
        (
            [id] => 5
            [name] => 综合服务
            [indexSub] => 3
            [services] => Array
                (
                )
)
)
如果发现Scat[key][indexSub]==topcat[id],则输出Scat[key][services][key][name]


不懂我表达清楚没有。。。。。

2012-03-18 18:41:10

#2 jake

因为看不是很懂,只能给出大概解决方法,建议是看smarty手册关于变量赋值的章节就明白了http://www.smarty.net/docs/en/language.syntax.variables.tpl
http://www.smarty.net/docs/en/language.function.foreach.tpl

<{foreach $Scat as $sitem}>

<{if $sitem.indexSub == $topcat.<{$sitem.id}>}>

输出是:<{$sitem.services.<{$sitem@index}>.name)>

<{endif}>

<{endforeach}>

2012-03-18 21:02:49

#3 prince

谢谢jake指点,这个foreach   as真好用
我用的是smarty2的手册所以没有看到这种循环方法,这个很明了
数组名称跟我上边发的不一样
循环代码:
<{foreach $indexmodule as $iid}>
                        
                        <{/foreach}>
效果($Scat这个不需要显示):
20120319193121.jpg

2012-03-19 19:29:12