Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to get property 'id' of non-object {"exception":"[object]

i have a $data= [{"id":54,"systemid":"1610000060000000063"}]and i am trying to get id like this
$id = $data['id'] and even i tried $data->id and i am getting Trying to get property ‘id’ of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property ‘id’ of non-object)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you have an array in json format:

 $array='[{"id":54,"systemid":"1610000060000000063"}]';

first you have to decode the array:

$decodedArray=json_decode($array);

then get the element at index 0:

    $object=$decodedArray[0];

then you can get it’s id:

    $id=$object->id;

see the sandbox for it:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading