简体   繁体   中英

How to fetch value of stdClass Object inside value?

stdClass Object
(
   [net_type] => Net 1
   [No of Windows] => 2
   [0] => stdClass Object
    (
        [Windows1] => stdClass Object
            (
                [Width1] => 20
                [Height1] => 10
            )

        [Windows2] => stdClass Object
            (
                [Width2] => 40
                [Height2] => 15
            )

    )

   [Pricing/sq ft] => 20
   [Total Area] => 2
   [Total Price] => 5
)

I know to get value of net_type :

$details_decode = json_decode($details);
echo "details==".$details_decode->net_type;

But how to get value of Width1 ie:

echo "windows 1==".$details_decode->Windows1['Width1'];

You are probably best to pass a second ( true ) parameter with json_decode :

When TRUE, returned objects will be converted into associative arrays.

ie:

$details_decode = json_decode($details, true);

And then access it like an array, this is better since some of the object properties have spaces in them. eg:

$details_decode['net_type']
$details_decode[0]['Windows1']
$details_decode['Pricing/sq ft']

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM