Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Creating the Catalog Array 4:43
- Adding Elements and Specifying a Key 3:20
- Introducing Arrays 4 objectives
- Associative Arrays 5:30
- Associative Arrays 7 objectives
- Displaying All Items 3:30
- Multidimensional Arrays 8 questions
- Creating the Display Function 4:56
- Working with Functions 8 questions
- Random Fun with Arrays 3:36
- Introducing Functions 1 objective
- Displaying Categories 5:50
- Sorting Array Items 6:05
- Item Details and Redirection 5:35
- Array Keys 2 objectives
- Displaying Item Details 5:55
- More Excitement With Arrays 6 questions
- Review Basics 3 objectives
- Wrapping It Up 0:45

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Now that you know how to grab specific items, the next step is to be able to sort those items to make it easier to check for a specific item.
Links
Steps Used for Sorting the Items
Step 1: Create an Associative Array for Sorting
Instead of $output being a simple indexed array, we will change this to an associative array with the key being the ID and the value being the item Title.
$sort = $item["title"];
$output[$id] = $sort;
Step 2: Sort the Array by Value and Return Only the Keys
asort($output);
return array_keys($output);
Step 3: Trim "The ", "A ", "An " from the beginning of the title
$sort = ltrim($sort,"The ");
$sort = ltrim($sort,"A ");
$sort = ltrim($sort,"An ");
Step 4: Sort the Full Catalog
To do this we will need to remove the early return from the function which was bypassing the sort. Instead, we will combine the two category conditionals. Either $category should be null (in this case we use every item) OR $category should match the item category.
if ($category == null OR strtolower($category) == strtolower($item["category"])) {
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
PLUS
Josh Coast
Courses Plus Student 5,297 Points2 Answers
-
Tom de Visser
2,522 Points3 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up