Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 1+;Smarty中的阵列输出_Loops_Foreach_Smarty - Fatal编程技术网

Loops 1+;Smarty中的阵列输出

Loops 1+;Smarty中的阵列输出,loops,foreach,smarty,Loops,Foreach,Smarty,我需要输出以下数组 对象(stdClass)#6(14){[“子类别”]=> 数组(9){[0]=>object(stdClass)#31(13){[“id”]=>string(2)“10” 字符串(1)[“名称”]=>字符串(8)“汤”[“描述”]=>字符串(0)”[“url”]=>字符串(4)”supy”[“元标题”]=>字符串(8)“汤”[“元关键字”]=>字符串(8)“汤”[“元描述”]=>字符串(0)”[“图像”=>字符串(0)”[“可见”=>字符串(1)“位置”=>字符串(1)”7“

我需要输出以下数组

对象(stdClass)#6(14){[“子类别”]=> 数组(9){[0]=>object(stdClass)#31(13){[“id”]=>string(2)“10” 字符串(1)[“名称”]=>字符串(8)“汤”[“描述”]=>字符串(0)”[“url”]=>字符串(4)”supy”[“元标题”]=>字符串(8)“汤”[“元关键字”]=>字符串(8)“汤”[“元描述”]=>字符串(0)”[“图像”=>字符串(0)”[“可见”=>字符串(1)“位置”=>字符串(1)”7“路径”=>数组(2)=>递归1]=>RECURSION}[“children”=>array(1){[0]=>int(10)}[1]=>object(stdClass){32(13){“id”=>string(2)“11”[“parent_id”]=>string(1)“6”[“name”=>string(12)“Саааааааааааааааааааааааааа1072=>array(1){[0]=>int(10)}[1]=>object(stdClass){[id]=>string(2)“11”[“parentаu id”=>string(1)“6”[“name”=>string(12)”Саааааааааааааааааааааааааааааа107]=>字符串(0)“[”可见“]=>字符串(1)“1”[”位置“]=>字符串(1)“8”[“路径”]=>数组(2){[0]=>递归[1]=>递归}

我认为这里有多个foreach需要输出[“子类别”]中的每个[“名称”]

现在我有了下面的代码

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

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

    </li>
{/foreach}
{foreach name=cats from=$category->name item=n}
  • {/foreach}
    仅显示当前类别(汤)的一个名称。
    如何从[“子类别”]中输出每个[“名称”]?

    正如您所说,每个级别都需要一个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}
    
    {foreach name=cats from=$category->name item=n}
    
  • {foreach name=subcats from=$n.subcategories item=s} .... {/foreach}
  • {/foreach}
    或者是from=$n->subcategories,我不确定,因为您将所有数组放在一行中,很难看到它