user995317
user995317

Reputation: 355

Getting string from array thats inside of an array

php isn't really my thing but I would need to get the votes and percentage from votes array.

stdClass Object
( 
[id] => 312
[type] => item-e
[votes] => Array
        (
            [plus] => Array
                (
                    [points] => Array
                        (
                            [votes] => 1
                            [percentage] => 100
                        )

                )

        )
)

I tried this:

$items->votes->plus->points->votes

But I get "Object of class stdClass could not be converted to string" -error message.

No need to loop it or something?

Upvotes: 1

Views: 56

Answers (2)

Cyclonecode
Cyclonecode

Reputation: 30001

You will have to access the array elements by key, something like this:

 $items->votes['plus']['points']['votes'];

Upvotes: 1

Till Helge
Till Helge

Reputation: 9311

You need to change some object attribute access notation to array access notation:

$items->votes['plus']['points']['votes']

Upvotes: 4

Related Questions