This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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 upRelated 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