Q:

how to access stdclass object in php?

This is my object:
$reportdata = stdClass Object
(
    [1] => stdClass Object
        (
            [reportname] => reportname1
            [reportviews] => 20
            [reportpath] => reports/reportname1
            [thumbnailurl] => reports/thumbnailurl/thumbnailurl1.jpg
            [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        )

    [2] => stdClass Object
        (
            [reportname] => reportname2
            [reportviews] => 20
            [reportpath] => reports/reportname2
            [thumbnailurl] => reports/thumbnailurl/thumbnailurl2.jpg
            [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        )

)

I am trying to access the individual values using $reportdata[1]['reportviews'] but I get an error 

"Cannot use object of type stdClass as array".

How can I access reportname and reportviews?

A:

Like this:
$reportdata->{1}->reportviews

A:

Try like this
 $reportdata=json_decode(json_encode($reportdata),true);

then use this
$reportdata[1]['reportviews']

You will not get any error.

