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
Arrays smarty中的处理阵列_Arrays_Loops_Smarty - Fatal编程技术网

Arrays smarty中的处理阵列

Arrays smarty中的处理阵列,arrays,loops,smarty,Arrays,Loops,Smarty,我正在尝试使用section命令访问smarty中的阵列。我想在smarty中使用section命令迭代1-128,但主要的是循环必须是65。现在,我可以使用$smarty.section.foo.index访问多达64个索引。我想使用一个常量{$lan.printer[$smarty.section.foo.index]+64}访问index>64中的值。但它不起作用。请帮我解决这个问题 我的代码如下 {section name=foo start=1 loop=65 step=1}

我正在尝试使用section命令访问smarty中的阵列。我想在smarty中使用section命令迭代1-128,但主要的是循环必须是65。现在,我可以使用$smarty.section.foo.index访问多达64个索引。我想使用一个常量{$lan.printer[$smarty.section.foo.index]+64}访问index>64中的值。但它不起作用。请帮我解决这个问题

我的代码如下

{section name=foo start=1 loop=65 step=1}
       {$lan.printer[$smarty.section.foo.index]}
       {$lan.printer[$smarty.section.foo.index]+64}
{/section}

提前感谢。

除了代码中明显的打字错误之外,要使用表达式作为数组的索引,您需要首先将其分配给变量,以便可以引用它:

{section name=foo start=1 loop=65 step=1}
   {assign var=offsetIndex value=$smarty.section.foo.index+64}
   {$lan.printer[$smarty.section.foo.index]}
   {$lan.printer[$offsetIndex]}
{/section}