0

When I uses objects in webapplications, sometimes I have to use $object->item, and sometimes I have to use: $object['item']. But what's the difference between both notations? When do I need the first notation, and when do I need the other notation?

user2753885
  • 59
  • 2
  • 5

1 Answers1

0

One is referencing an object:

echo $object->item;

In this case, you are echo'ing the property called 'item' within the object.

while the other is referencing an array:

echo $object['item'];

while in this case you are echo'ing the element with an associative index called 'item'.

I just wrote a half decent explanation of objects in another question which might be worth reading if you aren't sure about them (I really dislike to copy and paste answers).

Community
  • 1
  • 1
Fluffeh
  • 33,228
  • 16
  • 67
  • 80