Php Smarty foreach属性不工作
我试图使用各种smarty foreach属性,如last、first、total,但似乎没有任何效果。尽管循环工作正常。下面是我的代码:Php Smarty foreach属性不工作,php,foreach,smarty,Php,Foreach,Smarty,我试图使用各种smarty foreach属性,如last、first、total,但似乎没有任何效果。尽管循环工作正常。下面是我的代码: {foreach from=$myArray key=icon item=myValues name=myValueArray} {if $myValueArray.first} first element {/if} {$myValues["data"]} {/foreach} 我认为它一定很简单,所以我使用了link
{foreach from=$myArray key=icon item=myValues name=myValueArray}
{if $myValueArray.first} first element {/if}
{$myValues["data"]}
{/foreach}
我认为它一定很简单,所以我使用了link和so问题,但没有具体讨论这个问题。使用
{if$smarty.foreach.myValueArray.first}
。有使用{if$smarty.foreach.myValueArray.first}
。有使用{if$smarty.foreach.myValueArray.first}
。有使用{if$smarty.foreach.myValueArray.first}
。文档中有:
因此:
从文档:
因此:
从文档:
因此:
从文档:
因此:
{foreach} loops also have their own variables that handle properties.
These are accessed with: {$smarty.foreach.name.property} with “name” being
the name attribute.
Note
The name attribute is only required when you want to access a {foreach} property, unlike {section}. Accessing a {foreach} property with name undefined does not throw an error, but leads to unpredictable results instead.
{foreach} properties are index, iteration, first, last, show, total.
{foreach from=$myArray key=icon item=myValues name=myValueArray}
// {if $myValueArray.first} first element {/if}
{if $smarty.foreach.myValueArray.first} first element {/if}
{$myValues["data"]}
{/foreach}