-1
foreach($optionValue['productOptionValue'] as $value): // error here

endforeach;

The index already exists. Don't know what am I doing wrong.

  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
                                )

                        )

                )

Please help!!

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
nick_k
  • 107
  • 1
  • 8

1 Answers1

0

You have an object with the property "optionValues" inside as far as I can read. Lets assume your initial variable is called "$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
                            )

                    )

            )

So the following should do the trick:

foreach($sexy['optionValues'][34]['productOptionValue'] as $value):
    // I should be nice now and not throw an error here
endforeach;
chickahoona
  • 1,914
  • 14
  • 23