Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 948
Mátyás Grőger Avatar asked Sep 02 '25 16:09

Mátyás Grőger


1 Answers

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.

like image 174
gguney Avatar answered Sep 04 '25 07:09

gguney