Access property in stdClass Object [closed]
Asked Answered
M

1

12
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.

Motorbike answered 10/10, 2013 at 0:5 Comment(0)
P
14

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;
}
Polygyny answered 10/10, 2013 at 0:7 Comment(2)
its more good if you convert it into array from stdClass Object, then you can fetch any member very easily $value = get_object_vars($decodedvalues); $val = $value['ModuleAccountInfo']['0']['ServerName'];Curia
To me, it does not seem that $value['ModuleAccountInfo']['0']['ServerName'] is simpler than $moduleAccountInfo->ServerNameFriedly

© 2022 - 2024 — McMap. All rights reserved.