Solved

PHP: How to read array of objects?

Posted on 2013-01-09
3
229 Views
Last Modified: 2013-01-09
Dear Experts

Below is a print_r for an object.  echo $arr[0]['mtu'] does not work.

How can I get the data?

Array
(
    [0] => stdClass Object
        (
            [mtu] => 1500
            [hardwareAddress] => 00-FF-65-7E-63-B5
            [name] => {657E63B5-2B59-4893-83BB-A09BC8650E5D}
            [displayName] => Local Area Connection 3
            [active] =>
        )

    [1] => stdClass Object
        (
            [mtu] => 1500
            [hardwareAddress] => 00-06-4F-8B-59-2F
            [name] => {36A66546-CB58-4406-9A8C-42077286BF27}
            [displayName] => Wireless Network Connection
            [active] =>
        )

    [2] => stdClass Object
        (
            [mtu] => 1500
            [hardwareAddress] => 44-87-FC-77-29-1C
            [name] => {23B618D8-472A-4FF0-916F-014479753F93}
            [displayName] => Local Area Connection
            [active] => 1
        )

    [3] => stdClass Object
        (
            [mtu] => -1
            [hardwareAddress] =>
            [name] => {846EE342-7039-11DE-9D20-806E6F6E6963}
            [displayName] => Loopback Pseudo-Interface 1
            [active] => 1
        )

    [4] => stdClass Object
        (
            [mtu] => 1280
            [hardwareAddress] => 00-00-00-00-00-00-00-E0
            [name] => {6DEEA2EF-2807-442B-B843-4834A42AA41B}
            [displayName] => Teredo Tunneling Pseudo-Interface
            [active] => 1
        )

)

Open in new window

0
Comment
Question by:AdrianSmithUK
3 Comments
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 450 total points
ID: 38758879
It should be
$arr[0]->mtu;

Open in new window


You would be better off though assigning the obj to a var.

like this:
$tmpVar = $arr[0];

$mtu = $tmpVar->mtu;

Open in new window

0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 50 total points
ID: 38758890
Shouldn't it be:

echo $ arr[0]->mtu;

Open in new window

0
 

Author Closing Comment

by:AdrianSmithUK
ID: 38758979
Many thanks :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now