Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP: How to read array of objects?

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

926 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