4

What is exactly the difference between arrow operator -> and array indexing bracket[] ?

In my experience if we can do $obj->item; we always can do $obj['item'];

But not the other ways around.

1
  • 4
    -> is for objects and [] is for arrays and objects that implement ArrayAccess so no they are not interchangeable Commented Mar 3, 2022 at 8:14

1 Answer 1

3

You can use brackets with array but you cant use arrow for arrays. Array is data structure but object is stdClass in PHP. So, you can use object is like a normal class. You can use both for objects.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.