foreach($optionValue['productOptionValue'] as $value): // error here
endforeach;
索引已存在。 不知道我做错了什么。
Array
(
[optionValues] => Array
(
[34] => Array
(
[id_product_option] => 1
[option_value] => Hello
[required] => 1
[productOptionValue] => Array
(
[0] => Array
(
[id_product_option_value] => 1
[id_option_value] => 88
[quantity] => 12
[subtract] => 1
[price] => 232.0000
[price_prefix] => r
[weight] => 23.00000000
[weight_prefix] => k
)
)
)
请帮助!!
答案 0 :(得分:0)
据我所知,你有一个带有“optionValues”属性的对象。让我们假设你的初始变量叫做“$ sexy”:
$sexy = Array
(
[optionValues] => Array
(
[34] => Array
(
[id_product_option] => 1
[option_value] => Hello
[required] => 1
[productOptionValue] => Array
(
[0] => Array
(
[id_product_option_value] => 1
[id_option_value] => 88
[quantity] => 12
[subtract] => 1
[price] => 232.0000
[price_prefix] => r
[weight] => 23.00000000
[weight_prefix] => k
)
)
)
所以以下应该可以解决问题:
foreach($sexy['optionValues'][34]['productOptionValue'] as $value):
// I should be nice now and not throw an error here
endforeach;