0

I have the following array:

Cart Object
(
    [event_list] => Array
        (
            [15] => stdClass Object
                (
                    [event_id] => 15
                    [event_name] => North Pole Express 2014
                    [event_date] => 2014-12-06
                    [event_time] => 10:40:00
                    [event_ort_id] => 1
                    [ort_name] => Tanfield Railway
                    [ort_city] => Newcastle upon Tyne
                    [event_order_limit] => 0
                    [event_use_alt] => 
                )

            [14] => stdClass Object
                (
                    [event_id] => 14
                    [event_name] => North Pole Express 2014
                    [event_date] => 2014-11-30
                    [event_time] => 10:40:00
                    [event_ort_id] => 1
                    [ort_name] => Tanfield Railway
                    [ort_city] => Newcastle upon Tyne
                    [event_order_limit] => 0
                    [event_use_alt] => 
                )

            [13] => stdClass Object
                (
                    [event_id] => 13
                    [event_name] => North Pole Express 2014
                    [event_date] => 2014-11-29
                    [event_time] => 10:40:00
                    [event_ort_id] => 1
                    [ort_name] => Tanfield Railway
                    [ort_city] => Newcastle upon Tyne
                    [event_order_limit] => 0
                    [event_use_alt] => 
                )

        )

    [cat_list] => Array
        (
            [138] => stdClass Object
                (
                    [cat_id] => 138
                    [category_event_id] => 15
                    [cat_name] => Child - 4:00 pm
                    [cat_price] => 12.00
                    [cat_numbering] => none
                )

            [120] => stdClass Object
                (
                    [cat_id] => 120
                    [category_event_id] => 14
                    [cat_name] => Child - 4:00 pm
                    [cat_price] => 12.00
                    [cat_numbering] => none
                )

            [102] => stdClass Object
                (
                    [cat_id] => 102
                    [category_event_id] => 13
                    [cat_name] => Child - 4:00 pm
                    [cat_price] => 12.00
                    [cat_numbering] => none
                )

        )

    [disc_list] => Array
        (
        )

    [items] => Array
        (
            [4] => PlaceItem Object
                (
                    [id] => 4
                    [cart] => Cart Object
 *RECURSION*
                    [event_id] => 14
                    [category_id] => 120
                    [seats] => Array
                        (
                            [26151] => stdClass Object
                                (
                                    [seat_id] => 26151
                                    [seat_row_nr] => 0
                                    [seat_nr] => 0
                                    [seat_ts] => 1388769219
                                    [discount_id] => 0
                                )

                        )

                    [ts] => 
                    [created] => 2014-01-03T16:43:39+00:00
                    [expired] => 
                )

        )

    [ts] => 1388769219
)

I need to be able to access the 'Items' Key.

However everything I have tried so far has failed. I suspect I am missing something really obvious.

What would be the best way to access these items?

3
  • 2
    So, what have you tried that has not worked? We can't tell you what you are missing unless you show us what you've tried. Commented Jan 3, 2014 at 16:55
  • 1
    Since Cart is an object, have you tried $cart->items? Commented Jan 3, 2014 at 16:56
  • its an abject not an array: $myobj->items Commented Jan 3, 2014 at 16:56

2 Answers 2

3

Cart is not an array, it's an Object.

$cart = new Cart();
$cart->items; // <-- this is an array (of PlaceItems)
Sign up to request clarification or add additional context in comments.

1 Comment

Hi All, Ok, tired all the comments and I still can't get anywhere. I have used a variable to breakdown a bigger array/object. This is my current PHP $cCart = $_SESSION['_SMART_cart']; print_r($cCart); This is what I have used to extract the above array. Am I missing something really obvious?
1

Since $cart is an object you need to use object notation to access it, the arrays are underneath that:

forach ($cart->items as $key=>$value) {
  //...
}

Update from your comment:

$items=$_SESSION['_SMART_cart']->items;
foreach ($items as $key=>$value) {
   //...
}

1 Comment

Hi All, Ok, tired all the comments and I still can't get anywhere. I have used a variable to breakdown a bigger array/object. This is my current PHP $cCart = $_SESSION['_SMART_cart']; print_r($cCart); This is what I have used to extract the above array. Am I missing something really obvious?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.