Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP: How to read array of objects?

Posted on 2013-01-09
3
Medium Priority
?
239 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 1800 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 200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

721 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