Solved

PHP: How to read array of objects?

Posted on 2013-01-09
3
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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