Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 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
Sometimes we only want SOME of the objects in the collection. Enter filters. This is another piece of functionality or method to add to our collection class.
Array Functions
There are more advanced array functions that we could use to filter our array as well.
Array Map
Example:
$titles = array_map(
function ($recipe) {
return $recipe->getTitle();
},
$this->recipes
);
Array Filter
Example
$taggedRecipes = array_filter(
$this->recipes,
function ($recipes) use ($tag) {
return in_array(ucwords($tag),$recipes->getTagArray());
}
);
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Elinor Armsby
13,987 Points0 Answers
-
Oleksii Temchenko
3,474 Points2 Answers
-
PLUS
sujal khatiwada
Courses Plus Student 389 Points1 Answer
-
Stipe Stipic
17,520 Points0 Answers
-
Obayanju Damilare
3,383 Points1 Answer
-
Anam Hira
6,444 Points1 Answer
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