How to print properties of stdClass object in PHP?
Asked Answered
S

3

9

I have an array that contains standard class object. How can I return the properties (print them out) in a stdClass object?

Seer answered 14/10, 2011 at 2:45 Comment(1)
If you mean just displaying them for debugging or something, print_r or var_dump would both work.Bedcover
L
14

you should be able to see them using var_dump($myObject);

Lauder answered 14/10, 2011 at 2:48 Comment(0)
L
18

If you just want to print you can use var_dump() or print_r().

var_dump($obj);
print_r($obj);

If you want an array of all properties and their values use get_object_vars().

$properties = get_object_vars($obj);
print_r($properties);
Lastly answered 14/10, 2011 at 2:57 Comment(0)
L
14

you should be able to see them using var_dump($myObject);

Lauder answered 14/10, 2011 at 2:48 Comment(0)
W
3

I have solved this problem in this way:

echo $arrayName[0]->varname;

As it is an array of objects, we use -> to access objects attributes/methods.

Wivestad answered 29/10, 2019 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.