From the course: Functional Programming with PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Passing functions as arguments

Passing functions as arguments - PHP Tutorial

From the course: Functional Programming with PHP

Start my 1-month free trial

Passing functions as arguments

- [Instructor] Now that we've seen a few ways that we can treat functions in the same ways as other types, such as numbers, strings, and objects, the next step is to look at how we can pass functions as arguments to other functions. So up until now, you've probably been used to passing arguments into functions with the purpose of specifying what the data is that we're operating on. If we pass two numbers into a function called add, for example, we're specifying the two numbers that we want to add together. And likewise for subtract. But what if instead of passing arguments into our function to specify what our data is, we could pass in arguments to specify what was done to our data? In other words, because of first class functions, we're not only allowed to pass data into our functions, but we're allowed to pass functions into our functions as well. To illustrate this point, let's say that we have two very simple…

Contents