Reputation: 515
When i dd($MyArray);
I have a response like in the image
I'm asking why this code not working ?
$Id = $MyArray->id;
Error : Trying to get property 'id' of non-object
Upvotes: 0
Views: 44
Reputation: 1814
You can't access array element by ->
$MyArray['id'];
Or just convert array to object by
$newObject = (object)$MyArray;
$newObject->id;
Upvotes: 0
Reputation: 114
because it's not an object, so you should use the square bracket syntax $MyArray['id']
or cast it to an object ((object)$MyArray)->id
Upvotes: 3