Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Lucas Santos
19,315 PointsWhat's the difference between -> and => in php
I read that -> sets keys to values but I also know that => also sets keys to values in an array. I see the -> in loops like this foreach(loops as loop->black);
and many other places.
4 Answers
Kazimierz Matan
13,257 PointsGenerally:
=> is considered an array operator and is meant to be used with arrays
-> is an object operator and should be used in OOP (Object Oriented Programming) to call methods on objects.
Kazimierz Matan
13,257 Points<?php
class Products
{
public function getPrice()
{
// some code
}
}
$product = new Products;
$product->getPrice();
Last line of above code calls method named getPrice() on object named $product.

Lucas Santos
19,315 PointsI see ok so in other words the code within the function (method) would now be assigned to getPrice(); rite
Kazimierz Matan
13,257 PointsCode after public function getPrice()
, within brackets {}, is a body of getPrice method (function). It is executed every time you call this function, like $product->getPrice();
.

Lucas Santos
19,315 PointsOh I see ok got it thanks!
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsCan you give me a quick simple example of how I use -> to call methods on objects.