-2

Could someone explain to me the difference between using => or ->? Is there any logical difference? Thanks!

TheoretiCAL
  • 19,461
  • 8
  • 43
  • 65
  • If you can add into your question the case where you thought the two symbols might be interchangeable, that might make for a unique question. I should be interested to that code in any case. – halfer Jan 19 '14 at 19:49

1 Answers1

4

=> is used when defining arrays, and also in foreach loops that use keys, e.g.

$foo = array('bar' => 'baz');
foreach ($array as $key => $value) {...}

-> is used to refer to object members, e.g.

$obj->method();
$obj->property;

They are never interchangeable.

George Brighton
  • 5,131
  • 9
  • 27
  • 36