0

For the life of me I can not figure out how to access the values of this array. Every example the stdClass Object has some type of value. If I try for example $obj->0->0->city; I get an error.

Can someone show me a example how to access [city] => toronto or even [date_created] => 2011-05-03 14:33:58?

I also tried this with no luck.

$object = $buy[1]; 
$title = $object->title[0];
echo "$title";

Thanks

This is what the api gives me.

stdClass Object
(
    [id] => 1
    [name] => toronto
    [date_modified] => 2011-03-08 13:07:10
    [tax_rate_provincial] => 
)
<br/> 
Array
(
    [0] => stdClass Object
        (
            [0] => stdClass Object
                (
                    [id] => 28131844
                    [full_date] => 20110506
                    [end_date] => 20110511
                    [city] => toronto
                    [saved] => 1651
                    [discount_percentage] => 52
                    [deal_option] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [id] => 2600
                                    [title] => 
                                    [date_modified] => 0000-00-00 00:00:00
                                    [date_created] => 2011-05-03 14:33:58
                                    [value] => 3150
                                    [price] => 1499
                                    [deal_id] => 28131844
                                    [is_default] => 0
                                )

                        )

                    [options] => 
                    [option_quantity] => 
                    [option_remaining] => 
                    [purchase_limit] => 1
                    [gift_limit] => 0
0

1 Answer 1

2

There is a special evil syntax to bypass numeric object attributes:

 print $obj->{'0'}->{'0'}->city;

Is the correct syntax, and equivalent to the path you already determined.

Your second example is an array however, so it's probably:

 print $array[0]->{'0'}->city;

The alternative is always to just foreach over a specific level - that works for objects and arrays likewise.

Sign up to request clarification or add additional context in comments.

Comments

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.