3

I'm unfamiliar with exact differences between these two operators:

->

and

=>

Are there many differences? One assigns an array, and the other just renames or something to that effect?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Head Way
  • 323
  • 2
  • 4
  • 16

3 Answers3

6

-> is a method call or property call operator, and => is an array assigning operator

$foo = new Bar();
$foo->test();
// or even
$foo->bar = 'baz';

// vs 

$foo = array(
    'bar' => 'test'
);

// And wrapping it all together!!!
$foo = new Bar();
$foo->baz = array( 'bar' => 'baz' );
Ascherer
  • 8,223
  • 3
  • 42
  • 60
0

-> is a this operator which is used for accessing class properties whereras

=> is a used for arrays

chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
0

-> is used to access a property of an object where as => is used to marry a array key up with its value during assignment.

Orangepill
  • 24,500
  • 3
  • 42
  • 63