【发布时间】:2014-06-23 19:03:09
【问题描述】:
我有一个名为 $rebate_by_product 的数组:
Array
(
[op] => preview
[id] =>
[form_submitted] => yes
[company_id] => 46
[1] => Array
(
[pack] => 10
[quantity] => 20
[volume] => 30
[units] => 9
[amount] => 40
[rebate_start_date] => 2014-05-01
[rebate_expiry_date] => 2014-05-05
[applicable_states] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[rebate_total_count] => 5000
[products] => Array
(
[1] => 9
[2] => 10
)
)
[2] => Array
(
[pack] => 50
[quantity] => 60
[volume] => 70
[units] => 10
[amount] => 80
[rebate_start_date] => 2014-05-06
[rebate_expiry_date] => 2014-05-10
[applicable_states] => Array
(
[0] => 14
[1] => 15
[2] => 16
)
[rebate_total_count] => 10000
[products] => Array
(
[1] => 11
[2] => 8
)
)
[3] => Array
(
[pack] => 100
[quantity] => 200
[volume] => 300
[units] => 7
[amount] => 400
[rebate_start_date] => 2014-05-21
[rebate_expiry_date] => 2014-05-30
[applicable_states] => Array
(
[0] => 26
[1] => 33
[2] => 42
)
[rebate_total_count] => 9999
[products] => Array
(
[1] => 9
[2] => 8
)
)
[multiselect] => 42
)
你可以从上面的数组中观察到它有几个不是数组的元素,但它有三个这样的元素,它们本身就是数组,甚至它的少数数据元素也是数组,所以如何使用 foreach 循环遍历这种数组?
【问题讨论】:
-
是的,我们可以看到有些是数组,有些不是,那么目标是什么?循环它们,接下来会发生什么?请澄清您的问题并提供目标和最终结果
-
@kevinabelita:我想访问每个值并使用 foreach 循环打印它们。
标签: php arrays foreach associative-array key-value