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! While you're at it, check out some resources Treehouse students have shared here.

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

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Sorting Array Items

Amy Hsieh
Amy Hsieh
6,023 Points

What information is really stored in $sort = $item["title"] ?

In $sort = $item["title"],

I guess $sort is an array, which stores all the titles of all the items, and we sort the titles within this array?

2 Answers

jamesjones21
jamesjones21
9,260 Points

the $item['title'] will be stored into the $sort variable, so it's passing responsibility from right to left. If you var_dump($sort) you'll see what is inside the variable.

Amy Hsieh
Amy Hsieh
6,023 Points

Thanks for clarification. So in Variable $sort , are there 12 elements (the titles of 12 items), which makes $sort an array?

jamesjones21
jamesjones21
9,260 Points

if you do the following:

this little function will tell you the type of $sort (can show, int, string, float, bool or array). If you remove the gettype function, then it will show you the contents of $sort, which more than likely be the array.

var_dump(gettype($sort));
Amy Hsieh
Amy Hsieh
6,023 Points

Thanks, I tried both var_dump ($sort) and var_dump(gettype($sort)); The result from var_dump ($sort) as below seems to me that $sort is an array which has 4 elements (but I am wondering why not 12 elements from all items?) :

string(64) "A Design Patterns: Elements of Reusable Object-Oriented Software" string(54) "Clean Code: A Handbook of Agile Software Craftsmanship" string(50) "Refactoring: Improving the Design of Existing Code" string(63) "The Clean Coder: A Code of Conduct for Professional Programmers"

Am I right? Do you think it's an array?

jamesjones21
jamesjones21
9,260 Points

That is an array yes.