echoing something from multidimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naggi
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 7:01 am

echoing something from multidimensional array

Post by naggi »

I have an array that looks like this if I use print_r:

Code: Select all


print_r($row);

Array ( [0] => stdClass Object ( [id] => 4 ))
How I can echo that id out?

echo $row->id doesnt seem to work.
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Re: echoing something from multidimensional array

Post by Corvin »

Code: Select all

echo $row[0]->id;
Last edited by Corvin on Thu Jul 21, 2011 9:48 am, edited 1 time in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: echoing something from multidimensional array

Post by AbraCadaver »

The array item is an object and id is a property of that object:

Code: Select all

echo $row[0]->id;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
naggi
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 7:01 am

Re: echoing something from multidimensional array

Post by naggi »

Oh cool that works! Nice thanks.

How about if there is second array inside. How to echo that one?

Code: Select all

Array ( [0] => Array ( [0] => stdClass Object ( [id] => 3 )))
naggi
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 7:01 am

Re: echoing something from multidimensional array

Post by naggi »

That was quick. Was just replying to my own post that I figured it out but thanks for the answer.
Post Reply