如何在foreach函数下正确提取下面的元素。我尝试不同的方式,我可以提取元素,但不是$product_option_value_data
。
我有这个元素
$data['options'] = [];
$products_option_value = [];
foreach ($product_option_value as $products_value) {
$product_option_value_data[] = ['products_option_value_id' => $products_value['products_option_value_id'],
'option_value_id' => $products_value['option_value_id'],
'name' => $products_value['name'],
'image' => $products_value['image'],
'quantity' => $products_value['quantity'],
'subtract' => $products_value['subtract'],
'price' => $products_value['price'],
'price_prefix' => $products_value['price_prefix'],
'weight' => $products_value['weight'],
'weight_prefix' => $products_value['weight_prefix'],
'customers_group_id' => $products_value['customers_group_id'],
'products_option_model' => $products_value['customers_group_id'],
'option_tax_class_id' => $products_value['customers_group_id']
];
}
$data['options'][] = [
'products_option_id' => $value['products_option_id'],
'option_id' => $value['option_id'],
'name' => $value['name'],
'type' => $value['type'],
'value' => $value['value'],
'required' => $value['required'],
'products_option_value' => $product_option_value_data
];
}
$product_option_value_data
是一个元素可以在数组
array (size=2)
0 =>
array (size=13)
'products_option_value_id' => string '171' (length=3)
'option_value_id' => string '179' (length=3)
'name' => string 'S' (length=1)
'image' => null
'quantity' => string '100' (length=3)
'subtract' => string '0' (length=1)
'price' => string '1.0000' (length=6)
'price_prefix' => string '+' (length=1)
'weight' => string '0.00' (length=4)
'weight_prefix' => string '+' (length=1)
'customers_group_id' => string '99' (length=2)
'products_option_model' => string '99' (length=2)
'option_tax_class_id' => string '99' (length=2)
1 =>
array (size=13)
'products_option_value_id' => string '170' (length=3)
'option_value_id' => string '180' (length=3)
'name' => string 'M' (length=1)
'image' => null
'quantity' => string '100' (length=3)
'subtract' => string '0' (length=1)
'price' => string '0.0000' (length=6)
'price_prefix' => string '+' (length=1)
'weight' => string '0.00' (length=4)
'weight_prefix' => string '+' (length=1)
'customers_group_id' => string '99' (length=2)
'products_option_model' => string '99' (length=2)
'option_tax_class_id' => string '99' (length=2)
我写了一个这样的循环,但它不起作用,我无法提取
$product_option_value_data
元素
$options = $data['options'];
foreach ($options as $option) {
if ($option['type'] == 'select') {
echo $option['products_option_value_id'];
echo $option['name'];
}
}
谢谢
要显示值products_option_value,我必须在数组
中写入$data['options'][] = [
'products_option_value' => $product_option_value_data[0]
];
[0]
不是唯一的值,我可以让其他人看到上面的
结果:
array (size=7)
0 =>
array (size=7)
'products_option_id' => string '213' (length=3)
'products_option_value' =>
array (size=9)
'products_option_value_id' => string '171' (length=3)
'option_value_id' => string '179' (length=3)
'name' => string 'S' (length=1)
'image' => null
'price' => string ' 0.20 EUR' (length=19)
'price_prefix' => string '+' (length=1)
'customers_group_id' => null
'products_option_model' => null
'option_tax_class_id' => null
'option_id' => string '40' (length=2)
'name' => string 'Taille' (length=6)
'type' => string 'select' (length=6)
'value' => null
'required' => null
1 =>
array (size=7)
'products_option_id' => string '212' (length=3)
'products_option_value' =>
array (size=9)
'products_option_value_id' => string '171' (length=3)
'option_value_id' => string '179' (length=3)
'name' => string 'S' (length=1)
'image' => null
'price' => string ' 0.20 EUR' (length=19)
'price_prefix' => string '+' (length=1)
'customers_group_id' => null
'products_option_model' => null
'option_tax_class_id' => null
'option_id' => string '40' (length=2)
'name' => string 'Taille' (length=6)
'type' => string 'select' (length=6)
'value' => null
'required' => null
否则我有。
array (size=7)
0 =>
array (size=7)
'products_option_id' => string '213' (length=3)
'products_option_value' =>
array (size=13)
0 =>
array (size=9)
...
1 =>
array (size=9)
...
2 =>
array (size=9)
...
3 =>
array (size=9)
...
4 =>
array (size=9)
...
5 =>
array (size=9)
...
6 =>
array (size=9)
...
7 =>
array (size=9)
...
8 =>
array (size=9)
...
9 =>
array (size=9)
...
10 =>
array (size=9)
...
11 =>
array (size=9)
...
12 =>
array (size=9)
...
'option_id' => string '40' (length=2)
'name' => string 'Taille' (length=6)
'type' => string 'select' (length=6)
'value' => null
'required' => null
1 =>
array (size=7)
'products_option_id' => string '212' (length=3)
'products_option_value' =>
array (size=13)
0 =>
array (size=9)
...
1 =>
array (size=9)
...
2 =>
array (size=9)
...
3 =>
array (size=9)
...
4 =>
array (size=9)
...
5 =>
array (size=9)
...
6 =>
array (size=9)
...
7 =>
array (size=9)
...
8 =>
array (size=9)
...
9 =>
array (size=9)
...
10 =>
array (size=9)
...
11 =>
array (size=9)
...
12 =>
array (size=9)
...
'option_id' => string '40' (length=2)
'name' => string 'Taille' (length=6)
'type' => string 'select' (length=6)
'value' => null
'required' => null