Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从smarty中的关联数组访问和循环内部数组的元素?_Php_Arrays_Smarty_Associative Array - Fatal编程技术网

Php 如何从smarty中的关联数组访问和循环内部数组的元素?

Php 如何从smarty中的关联数组访问和循环内部数组的元素?,php,arrays,smarty,associative-array,Php,Arrays,Smarty,Associative Array,我有一个名为preview_data的关联数组,它是从PHP分配给smarty模板的: Array ( [op] => preview [id] => [form_submitted] => yes [company_id] => 46 [1] => Array ( [product_id_1] => Array (

我有一个名为preview_data的关联数组,它是从PHP分配给smarty模板的:

Array
(
    [op] => preview
    [id] => 
    [form_submitted] => yes
    [company_id] => 46
    [1] => Array
        (
            [product_id_1] => Array
                (
                    [1] => 8
                    [2] => 11
                )

            [pack] => 10
            [quantity] => 20
            [volume] => 30
            [units] => 7
            [amount] => 40
            [rebate_start_date] => 2014-05-02
            [rebate_expiry_date] => 2014-05-31
            [applicable_states] => Array
                (
                    [0] => 1
                    [1] => 8
                    [2] => 16
                    [3] => 23
                )

            [rebate_total_count] => 5000
        )

    [2] => Array
        (
            [pack] => 100
            [quantity] => 200
            [volume] => 300
            [units] => 9
            [amount] => 80
            [rebate_start_date] => 2014-06-01
            [rebate_expiry_date] => 2014-06-30
            [applicable_states] => Array
                (
                    [0] => 32
                    [1] => 39
                    [2] => 43
                    [3] => 47
                    [4] => 49
                )

            [rebate_total_count] => 10000
            [product_id_2] => Array
                (
                    [1] => 9
                    [2] => 10
                )

        )

    [3] => Array
        (
            [pack] => 500
            [quantity] => 1000
            [volume] => 1500
            [units] => 10
            [amount] => 2000
            [rebate_start_date] => 2014-08-01
            [rebate_expiry_date] => 2014-09-30
            [applicable_states] => Array
                (
                    [0] => 12
                    [1] => 28
                    [2] => 43
                    [3] => 49
                    [4] => 50
                )

            [rebate_total_count] => 9000
            [product_id_3] => Array
                (
                    [1] => 8
                    [2] => 11
                )

        )

    [multiselect] => 50
)

如何在smarty中访问和循环内部数组元素。我是指索引为1,2,3,。。。另外,请解释如何访问内部数组本身的内部元素,例如[适用状态],[产品id]。提前谢谢

再次检查int和than循环

PHP

为Smarty试一试:

{foreach from=$array key=key item=innerArray}
  {if is_int($key)}
     {foreach from=$innerArray key=innerKey item=innerValue}
        {$innerValue.applicable_states}
     {/foreach}
  {/if}
{/foreach}

您已经向我展示了如何使用PHP。我想要使用Smarty访问、循环和打印上述阵列的方法。你能为我提供智能解决方案吗?
{foreach from=$array key=key item=innerArray}
  {if is_int($key)}
     {foreach from=$innerArray key=innerKey item=innerValue}
        {$innerValue.applicable_states}
     {/foreach}
  {/if}
{/foreach}