Solved

PHP: How to read array of objects?

Posted on 2013-01-09
3
230 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 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 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

14 Experts available now in Live!

Get 1:1 Help Now