我在这段代码上有这个错误: 任何的想法 ? 非法字符串偏移'类型'
foreach ($_POST['product_option'] as $product_option) {
var_dump( $product_option['type']);
$type = $product_option['type'];
if ($type == 'file') {
$value_type = 'file';
} elseif ($type == 'textarea') {
$value_type = 'textarea';
} else {
$value_type = $type;
}
}
var_dump($product_option['type'])
:
Save.php:61:string 'radio' (length=5)
Save.php:61:string 'select' (length=6)
Save.php:61:string 'checkbox' (length=8)
Save.php:61:string 'textarea' (length=8)
$product_option
数组(大小= 3) ' option_id' =>字符串' 43' (长度= 2) '类型' =>字符串' radio' (长度= 5)
Save.php:60: array (size=2) 'option_id' => string '44' (length=2) 'type' => string 'select' (length=6) Save.php:60: array (size=2) 'option_id' => string '47' (length=2) 'type' => string 'checkbox' (length=8) Save.php:60: array (size=2) 'option_id' => string '55' (length=2) 'type' => string 'file' (length=4)
答案 0 :(得分:1)
您目前没有使用$_POST['product_option'][x]
作为foreach迭代。有x个元素都包含一个类型元素。
更改
$type = $_POST['product_option']['type'];
到
$type = $product_option['type'];