Advertisement
Advertisement


What Does This Mean in PHP -> or =>


Question

Possible Duplicate:
where we use object operator “->” in php
Reference - What does this symbol mean in PHP?

I see these in PHP all the time but I don't have a clue as to what they actually mean. What does -> do and what does => do. And I'm not talking about the operators. They're something else, but nobody seems to know...

2017/05/23
1
168
5/23/2017 11:47:26 AM


=> is used in associative array key value assignment. Take a look at:

http://php.net/manual/en/language.types.array.php.

-> is used to access an object method or property. Example: $obj->method().

2012/12/26

-> is used to call a method on the object of a class

=> is used to assign values to the keys of an array

E.g.:

$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34, 1=>2); 

->

calls/sets object variables. Ex:

$obj = new StdClass;
$obj->foo = 'bar';
var_dump($obj);

=> Sets key/value pairs for arrays. Ex:

$array = array(
    'foo' => 'bar'
);
var_dump($array);
2012/12/26