0

我需要输出以下数组

object(stdClass)#6 (14) { ["subcategories"]=> array(9) { [0]=> object(stdClass)#31 (13) { ["id"]=> string(2) "10 " ["parent_id"]=> string(1) "6" ["name"]=> string(8) "Soup" ["description"]=> string(0) "" ["url"]=> string (4) "supy" ["meta_title"]=> string(8) "Soup" ["meta_keywords"]=> string(8) "Soup" ["meta_description"]=> string(0) "" ["image "]=> string(0) "" ["visible"]=> string(1) "1" ["position"]=> string(1) "7" ["path"]=> array(2) { [0]=>递归[1]=>递归} ["children"]=> array(1) { [0]=> int(10) } } [1]=> object(stdClass)#32 (13) { ["id"]=> string(2) "11" ["parent_id"]=> string(1) "6" ["name"]=> string(12) "Сашими" ["description"]=> string(0) "" ["url"]= > string(7) "sashimi" ["meta_title"]=> string(12) "Сашими" ["meta_keywords"]=> string(12) "Сашими" ["children"]=> array(1) { [0 ]=> int(10) } } [1]=> object(stdClass)#32 (13) { ["id"]=> string(2) "11" ["parent_id"]=> string(1) " 6" ["name"]=> string(12) "Сашими" ["description"]=> string(0) "" ["url"]=> string(7) "生鱼片" ["meta_title"]=> string(12) "Сашими" ["meta_keywords"]=> string(12) "Сашими" ["meta_description"]=> string(0) "" ["image"]=> string(0) "" ["visible"]=> string(1) "1" ["position"]=> string(1) "8" ["path"]=> array(2) { [0]=> RECURSION [1 ]=>递归}递归}递归}

我认为这里有多个 foreach 需要从 ["subcategories"] 输出每个 ["name"]

现在我有以下代码

 {foreach name=cats from=$category->name item=n}

    <li>
        <a href="catalog/{$n->url}" category_id="{$n->id}">
            <b>{$n}</b>
        </a>

    </li>
{/foreach}

仅显示当前类别(汤)的一个名称。如何从 ["subcategories"] 输出每个 ["name"] ?

4

1 回答 1

0

正如你所说,每个级别都需要一个 foreach :

 {foreach name=cats from=$category->name item=n}

    <li>
        <a href="catalog/{$n->url}" category_id="{$n->id}">
            <b>{$n}</b>
        </a>
        {foreach name=subcats from=$n.subcategories item=s}        
        ....
        {/foreach}


    </li>
{/foreach}

或者可能是from=$n->subcategories,我不确定,因为您将所有数组放在一行中并且很难看到它

于 2013-05-08T08:36:38.647 回答