0

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

1
  • 1
    Because the syntaxis to get an Array element by index is $MyArray['id']. This other syntaxis $MyArray->id; is to get Object attributte Commented Oct 6, 2019 at 19:29

3 Answers 3

3

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

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

Comments

1

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

Comments

0

You can't access array element by ->

 $MyArray['id'];

Or just convert array to object by

 $newObject = (object)$MyArray;
 $newObject->id;

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.