>

루프가 작동하지 않고이 오류가 발생합니다 :

와이즈 비즈 와이즈 비즈

문제의 요소는

Invalid argument supplied for 입니다

foreach()

값 :

$option['products_option_value']

내 코드

$options_array

array (size=4) 0 => array (size=7) 'products_option_id' => string '406' (length=3) 'option_id' => string '42' (length=2) 'name' => string 'Couleur' (length=7) 'type' => string 'select' (length=6) 'value' => null 'required' => null 'products_option_value' => array (size=13) 'products_option_value_id' => string '279' (length=3) 'option_value_id' => string '186' (length=3) 'name' => string 'Vert' (length=4) 'image' => null 'quantity' => string '0' (length=1) '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 '0' (length=1) 'products_option_model' => string '' (length=0) 'option_tax_class_id' => string '0' (length=1) 1 => array (size=7) 'products_option_id' => string '405' (length=3) 'option_id' => string '42' (length=2) 'name' => string 'Couleur' (length=7) 'type' => string 'select' (length=6) 'value' => null 'required' => null 'products_option_value' => array (size=13) 'products_option_value_id' => string '278' (length=3) 'option_value_id' => string '187' (length=3) 'name' => string 'Red' (length=3) 'image' => null 'quantity' => string '0' (length=1) '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 '0' (length=1) 'products_option_model' => string '' (length=0) 'option_tax_class_id' => string '0' (length=1) 2 => array (size=7) 'products_option_id' => string '402' (length=3) 'option_id' => string '40' (length=2) 'name' => string 'Taille' (length=6) 'type' => string 'select' (length=6) 'value' => null 'required' => null 'products_option_value' => array (size=13) 'products_option_value_id' => string '275' (length=3) 'option_value_id' => string '180' (length=3) 'name' => string 'M' (length=1) 'image' => null 'quantity' => string '0' (length=1) 'subtract' => string '0' (length=1) 'price' => string '20.0000' (length=7) 'price_prefix' => string '+' (length=1) 'weight' => string '0.00' (length=4) 'weight_prefix' => string '+' (length=1) 'customers_group_id' => string '0' (length=1) 'products_option_model' => string '' (length=0) 'option_tax_class_id' => string '0' (length=1) 3 => array (size=7) 'products_option_id' => string '401' (length=3) 'option_id' => string '40' (length=2) 'name' => string 'Taille' (length=6) 'type' => string 'select' (length=6) 'value' => null 'required' => null 'products_option_value' => array (size=13) 'products_option_value_id' => string '274' (length=3) 'option_value_id' => string '180' (length=3) 'name' => string 'M' (length=1) 'image' => null 'quantity' => string '0' (length=1) '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 '0' (length=1) 'products_option_model' => string '' (length=0) 'option_tax_class_id' => string '0' (length=1)

  • 답변 # 1

    isset 를 사용해야합니다  내부를 확인하기 위해

       foreach ($options_array as $option) {
            $product_option_value_data = [];
              foreach ($option['products_option_value'] as $option_value) {
    // Change below IF 
                if ((isset($option_value['subtract']) && !empty($option_value['subtract'])) || ($option_value['quantity'] > 0)) {
                   $product_option_value_data[] =  ['products_option_value_id' => $option_value['products_option_value_id'],
                                                   'option_value_id'         => $option_value['option_value_id'],
                                                   'name'                    => $option_value['name'],
                                                   'image'                   => $option_value['image'],
                                                   'quantity'                => $option_value['quantity'],
                                                   'price'                   => $option_value['price'],
                                                   'price_prefix'            => $option_value['price_prefix'],
                                                   'products_option_model'   => $option_value['products_option_model'],
                                                  ];
                }
              }
    
    

  • 이전 ASPNET MVC에서 Razor를 사용하여 텍스트 상자에 변수 값을 삽입하는 방법
  • 다음 android - Google 드라이브에 저장된 PDF 파일을 WebView에 표시