0

What is the difference between => and -> in php? and when i should use those ? i know that -> can be use in object like $obj->foo and => is in array is there any other place we can use them ?

  • 3
    [reference-what-does-this-symbol-mean-in-php](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – Your Common Sense Apr 28 '13 at 11:48

3 Answers3

1

As chandresh said but with examples:

=> is for associative arrays. You would do such:

$arr = array("key" => "value"); // now value can be access simply by typing $arr['key'];

-> is for accessing object properties(variables) and methods(functions)

// instead of doing this:
calculate();

// if you have created an object, you could access the method(function) like so:

$object->calculate();  // to call method(function) inside a class\object
half-fast
  • 182
  • 7
0

One is a scope resolution operator and the other is an array control method to define Keys/values

What's the difference between :: (double colon) and -> (arrow) in PHP? For the -> syntax and:

What does "=>" mean in PHP? for the => syntax

Community
  • 1
  • 1
Daryl Gill
  • 5,238
  • 7
  • 31
  • 68
0

Below link will provide you a full list of symbols and their usage.

Reference - What does this symbol mean in PHP?

Since you have asked, In short

=> is called T_DOUBLE_ARROW and is the separator for associative arrays, the '=>' created key/value pairs.

-> is called "object operator" or T_OBJECT_OPERATOR and it's used when you want to call a method on an instance or access an instance property.

Community
  • 1
  • 1
Techie
  • 42,101
  • 38
  • 144
  • 232