smarty 获取数组的偏移量

smarty get offset of array

我在使用 smarty 的 prestashop 1.6 中遇到了一些问题。

我有一个数组,但它的偏移量没有为每个产品重置。

因此对于第一个产品,具有属性的偏移量为 1,2,3,4 然后对于下一个产品,它的偏移量为 5,6,7,8 等

我有那种数组

$combinations   Smarty_Variable Object (3)
->value = Array (4)
  5 => Array (14)
    attributes_values => Array (1)
      1 => "S"
    attributes => Array (1)
      0 => 1
    price => 0
    specific_price => Array (0)
    ecotax => 0
    weight => 0
    quantity => 20
    reference => ""
    unit_impact => 0
    minimal_quantity => "1"
    date_formatted => ""
    available_date => ""
    id_image => -1
    list => "'1'"
  6 => Array (14)

我尝试遍历这个数组,但是当我放置空偏移量时它不起作用(它在 foreach 中)

{$combinations[]['quantity']}

我如何告诉他通过第一次迭代,然后自动进入第二次迭代?

这return给我以下错误。

Fatal error: Cannot use [] for reading in /htdocs/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code on line 584

我无法告诉他使用哪个偏移量,因为对于每个产品它都会上升并且不会重置为 0。

如有任何帮助,我将不胜感激。

方法如下,current return 数组的第一个值

{$combination = current($combinations)}
{$combination['quantity']}

除了@UnLoCo 的回答,如果你需要这些键 1,2 ... 7,8

{foreach from=$array key=key item=value}
    {$key} => {$value}
{/foreach}

{foreach $array $key=>$value} {* like PHP style *}
        {$key} => {$value}
{/foreach}

Smarty 文档也可以帮助您 http://www.smarty.net/docs/en/language.function.foreach.tpl