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

Time:11-06

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)

CodePudding user response:

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:

  • Related