Tuesday 14 August 2018

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

0 comments:

Post a Comment