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
Since we want to choose the recipes from our meal plan, we need to be able to specify an individual recipe. Instead of trying to select the recipe based on the title, which can be long and easy to miss-type, we'll be setting things up to specify an id.
Open Ended Arguments
What if I want to be able to pass in any number of id's and return an array of those recipes. Besides explicitly calling a parameter, we can get an array of all the parameters using the func_get_args(). If we loop through that array of arguments, we can add each of those recipe arguments to the array our function will return.
public function addRecipeById()
{
foreach (func_get_args() as $id) {
$recipes[] = $this->recipes[$id];
}
}
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