user973917
user973917

Reputation:

How to print properties of stdClass object in PHP?

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

Upvotes: 9

Views: 35624

Answers (3)

LeandroIP
LeandroIP

Reputation: 41

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.

Upvotes: 3

Bailey Parker
Bailey Parker

Reputation: 15905

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);

Upvotes: 18

Brian Glaz
Brian Glaz

Reputation: 15686

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

Upvotes: 14

Related Questions