Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access property in stdClass Object [closed]

stdClass Object
(
[ModuleAccountInfo] => Array
    (
        [0] => stdClass Object
            (
                [ServerName] => EAST
                [HostingModule] => ActiveDirectory
                [ActiveDirectorySiteName] => EAST
                [AccountIdentity] => OU=ndla,OU=Hosting,DC=east,DC=domain,DC=local
                [Groups] => 2
                [Users] => 15
            )

        [1] => stdClass Object
            (
                [ServerName] => EAST.net
                [HostingModule] => hange
                [DiskQuota] => 375000
                [DiskQuotaAdditional] => 0
                [DateQuotaExceeded] => 0001-01-01T00:00:00
                [DiskSpace] => 58567
                [MailboxesDiskSpace] => 59973051
                [PublicFoldersDiskSpace] => 0
                [MessageArchivingDiskSpace] => 0
                [Contacts] => 8
                [Mailboxes] => 15

How do I access the ServerName properties? This object is held in a $modules variables. The above is the print_r of $modules.

like image 299
drack Avatar asked Oct 10 '13 00:10

drack


1 Answers

Because the ModuleAccountInfo property is an array, you'll either need to use a specific index

echo $modules->ModuleAccountInfo[0]->ServerName;

or loop

foreach ($modules->ModuleAccountInfo as $moduleAccountInfo) {
    echo $moduleAccountInfo->ServerName;
}
like image 140
Phil Avatar answered Oct 27 '22 17:10

Phil