Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: What is "->" and "=>"? [duplicate]

Tags:

syntax

php

Possible Duplicate:
Reference - What does this symbol mean in PHP?

I've been programming with PHP for a bit now, but every once in a while I run across these two expressions:

->
=>

What are these and what do they mean/do? I don't even know what to call them in order to find out...

like image 862
dcolumbus Avatar asked Nov 28 '25 09:11

dcolumbus


1 Answers

-> is used to access instance attributes of objects. It is the equivalent to the . syntax in many other languages (C, C++, Python, Javascript).

$myclass->my_instance_var;
$myclass->my_instance_method();

=> is used to map keys to values in associative arrays. It is the equivalent of : in a mapping in Python and Javascript.

$arr = Array("Hello" => "World", "Foo" => "Bar");
like image 110
Rafe Kettler Avatar answered Nov 29 '25 23:11

Rafe Kettler