What is the difference between => and
This question already has an answer here:
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.
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 classobject
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
上一篇: 有人可以解释我一个PHP代码
下一篇: =>和。之间的区别是什么?