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.

PHP Designing Interfaces in PHP Introducing Interfaces Implementing an Interface

Yotsaphon Sutweha
Yotsaphon Sutweha
2,621 Points

what's $data->$field means?

What's the meaning of $data->$field ?

2 Answers

Darrell Conklin
Darrell Conklin
21,507 Points

It's an associative array of objects. $data is an object. If the question is why is there a $ in front of $field when calling the property it's because we are using the value of the passed $field perameter as the property name.

So, if the value of $field = 'name'.

$data->$field is == $field->name.

Steven Parker
Steven Parker
218,832 Points

That's the PHP notation for a member of an associative array. The term on the left is the key, and the one on the right is the value.

You're in an intermediate-level course, which assumes a basic familiarity with the language. You might benefit from setting it aside and taking some of the fundamentals first. In particular, this notation and its use are covered in the PHP Arrays and Control Structures course.

Jojo Menzies
Jojo Menzies
14,085 Points

same question for me. I did the php arrays and what I can remember is the use of => for associative arrays. I thought -> is for an object and its properties and methods.