【发布时间】:2013-10-10 13:02:06
【问题描述】:
我想知道smarty中多维数组的长度。
我有:{foreach itme=$i from=$var}{/foreach}
我尝试使用{$var.$id|@count}
但不工作。
我怎样才能在{for} cicle 中使用这个长度?
【问题讨论】:
-
你的问题解决了吗?
标签: count smarty variable-length
我想知道smarty中多维数组的长度。
我有:{foreach itme=$i from=$var}{/foreach}
我尝试使用{$var.$id|@count}
但不工作。
我怎样才能在{for} cicle 中使用这个长度?
【问题讨论】:
标签: count smarty variable-length
你的逻辑很好。您在 foreach 循环中使用 @count 是正确的。但是您的代码包含一些错误。
{foreach itme=$i from=$var}{/foreach}
// ^----- should be item, $i should be just i without $ symbol in front
{$var.$id|@count}
// ^-------- this should be just $i according to your foreach loop and without $var.
所以功能代码应该是:
{foreach item=id from=$var}
{$id|count}
{/foreach}
请注意,在 Smarty 3 中,您不必在计数修饰符前添加 @ 符号。它只是被忽略了。
【讨论】: