doukuiqian9911 2016-07-31 15:29
浏览 32

Smarty:使用Array变量获取下一个索引

my array:

$array[0].item = '1'
$array[1].item = '2'
$array[2].item = '3'
...

Now I want get the Value of the Next Index: (counter methode)

{counter assign=i start=1 print=false}
{foreach $array as $myArray}
    var currentValue = {$myArray.item}; // currentValue = 1
    var nextValue = {$array[$i].item}; // doesn't work 
    {counter}
{/foreach}

The Variable $i is in the first loop exactly '1' but i cant use it for the Array as index, why?

  • 写回答

1条回答 默认 最新

  • douzhang3356 2016-08-02 11:48
    关注

    Try to use {section}: http://www.smarty.net/docsv2/en/language.function.section.tpl

    {counter start=1 print=false}
    {section name=i loop=$myArray}
        var currentValue = {$myArray[i].item};
        var nextValue = {$myArray[i.index_next].item|default:''};
        {counter}
    {/section}
    

    Make sure in your php code, you are doing proper assigning:

    $smarty->assign('myArray', $array); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料