简体   繁体   中英

Echo nested stdClass object inside array

The following data is stored as a PHP multidimensional array. How would I echo out " Reading/Social" from this array? This is my first experience playing around with multidimensional arrays and object oriented programming, so I'm not really sure where to start.

I have tried echo $roster[0]->class; but this does not work. What am I doing wrong?

Array
(
    [0] => stdClass Object
        (
            [class] => stdClass Object
                (
                    [alternateLink] => https://classroom.google.com/c/MjE5ODTA3NTc0
                    [calendarId] => c_classroom96eb75a@group.calendar.google.com
                    [courseGroupEmail] => test@school.org
                    [courseState] => ACTIVE
                    [creationTime] => 2021-01-02T17:28:07.444Z
                    [description] => 
                    [descriptionHeading] => 
                    [enrollmentCode] => sretszz
                    [guardiansEnabled] => 
                    [id] => 219850017574
                    [name] => 🔴 Reading/Social

The following data is stored as a PHP multidimensional array. How would I echo out " Reading/Social" from this array? This is my first experience playing around with multidimensional arrays and object oriented programming, so I'm not really sure where to start.

I have tried echo $roster[0]->class; but this does not work. What am I doing wrong?

Array
(
    [0] => stdClass Object
        (
            [class] => stdClass Object
                (
                    [alternateLink] => https://classroom.google.com/c/MjE5ODTA3NTc0
                    [calendarId] => c_classroom96eb75a@group.calendar.google.com
                    [courseGroupEmail] => test@school.org
                    [courseState] => ACTIVE
                    [creationTime] => 2021-01-02T17:28:07.444Z
                    [description] => 
                    [descriptionHeading] => 
                    [enrollmentCode] => sretszz
                    [guardiansEnabled] => 
                    [id] => 219850017574
                    [name] => 🔴 Reading/Social

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM