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
Luke Lee7,577 Points
How to use -> and =>
I have seen these 2 codes a lot in php files. What's the difference?
'href' => $this->url->link('common/home'), if (isset($this->request->get['path'])) $data = array( 'filter_category_id' => $category_id, 'filter_filter' => $filter, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit );
The -> is used to access properties and methods that are part of an Object in PHP.
In your example the $this variable is an object which contains the objects url and request.
The url object contains a function (considered a method when within an object) of link. The request object contains a variable (considered a property when within an object) of get which just so happens to be associative array which contains the variable 'path'.
The => is as far as I know only used to identify a key to a value in an associative array as shown in your example.
Hope that helps?