Search code examples
phplaravelannotationsoperators

difference between arrow operator (->) and array index bracket([]) in php


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.


Solution

  • 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.