Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Luke Lee
Luke Lee
7,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

1 Answer

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?