How to read stdClass object in php


 
How would I read this array (“stdClass Object”)

Object is not an array, but rather, well, an Object. So use the -> operator to access its properties:

If you currently have the following object:- [If you print your data and it will look like below]

stdClass Object
(
    [name] => Jainish Senjaliya
    [contact] => Array
        (
            [0] => stdClass Object
                (
		    [id] => 143
                    [email] => jainish.online@gmail.com
                    [URL] => http://www.hariomrubber.com
                    [phone] => 99******93
                )
        )
) 

For example, to get the name, you would do:

echo $data->name;
Output : Jainish Senjaliya

It contains a property which itself is an array of additional objects. For example, to get the URL of id 143, you would do:

echo $data->contact[0]->URL;

Output : http://www.hariomrubber.com

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

 


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s