0
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 i.e:

echo "windows 1==".$details_decode->Windows1['Width1'];
5
  • try $details_decode[0]->Windows1->Width1 Commented Jul 7, 2017 at 5:48
  • no, its not working Commented Jul 7, 2017 at 5:51
  • $details_decode->{'0'}->Windows1->Width1 Commented Jul 7, 2017 at 5:57
  • have you checked this? Commented Jul 7, 2017 at 6:02
  • I have checked, its not working Commented Jul 7, 2017 at 8:30

1 Answer 1

1

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

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

i.e.:

$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. e.g.:

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

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.