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?
Asked
Active
Viewed 268 times
0
-
So, in second case you are not using objects – Royal Bg Sep 09 '13 at 11:18
1 Answers
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).