PHP Build a Basic PHP Website Listing and Sorting Inventory Items Sorting Array Items

Amy Hsieh
Amy Hsieh
5,054 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

James Jones
James Jones
6,595 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
5,054 Points

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

James Jones
James Jones
6,595 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
5,054 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?

James Jones
James Jones
6,595 Points

That is an array yes.