yassine j
yassine j

Reputation: 515

Php/Laravel | Issue with array

When i dd($MyArray);

I have a response like in the image enter image description here

I'm asking why this code not working ?

$Id = $MyArray->id;

Error : Trying to get property 'id' of non-object

Upvotes: 0

Views: 44

Answers (3)

Jithesh Jose
Jithesh Jose

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

Manu-sh
Manu-sh

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

equi
equi

Reputation: 894

It is associative array. You access properties like: $MyArray['id']

Upvotes: 1

Related Questions