duan117890 2014-12-15 10:35
浏览 90
已采纳

在smarty中访问嵌套数组

I am trying to access a nested array inside html code using smarty. For example i have an array that looks like this: Array(customer)[name, age, id[firstname, lastname, birthdate]]. I have been trying something like this:

{foreach from=$customer item=foo} 
    Customer id: {$foo.id} 
{/foreach}

But this doesent print any values to the page. However with this syntax

{foreach from $customer item=foo}
    {$foo.id} // or {$foo.id.0}
{/foreach}

It prints out: Array

How do i access the values of nested array using smarty?

  • 写回答

2条回答 默认 最新

  • dounao1856 2014-12-15 10:39
    关注

    Try this:

    {foreach from=$customer item=foo} 
        Customer name: {$foo.id.firstname} {$foo.id.lastname}
    {/foreach}
    

    Smarty will compile it to something equivalent with:

    foreach ($customer as $foo) {
       echo('Customer name: '.$foo['id']['firstname'].' '.$foo['id']['laststname']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析