【问题标题】:How to access a hash inside an array in Smarty如何在 Smarty 中访问数组内的哈希
【发布时间】:2018-01-26 09:33:40
【问题描述】:

只是一个我无法通过 Google 找到的简单问题。 我有一个数组,其中一个元素有一个哈希。我想知道如何访问该哈希值:

这是数组

[tsh_promotion_details] =>
[{"id":"1","amount":10,"type":"product.percentage","product_price":69.9,"product_quantity":1}]

{$position.attributes.tsh_promotion_details|@print_r} 我收到了这个:

[{"id":"1","amount":10,"type":"product.percentage","product_price":69.9,"product_quantity":1}]

但我不知道如何获取金额。感谢您的帮助。

【问题讨论】:

    标签: arrays hash smarty


    【解决方案1】:

    我终于明白了。 如果有人在这里遇到类似的问题,解决方案: 基本上它是数组内的嵌套 json。 通过 Smarty 的 Json_decode,您可以将其转换为数组,然后像通常一样将其打印出来。

    {assign var=foo value=$position.attributes.tsh_promotion_details|json_decode}

    【讨论】:

      猜你喜欢
      • 2015-06-26
      • 1970-01-01
      • 1970-01-01
      • 2013-03-08
      • 2013-10-08
      • 2013-03-22
      • 2023-03-31
      • 2016-12-12
      • 1970-01-01
      相关资源
      最近更新 更多