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.

Challenge: Recreating the array_map function

Challenge: Recreating the array_map function - PHP Tutorial

From the course: Functional Programming with PHP

Start my 1-month free trial

Challenge: Recreating the array_map function

(upbeat music) - [Instructor] Now that we've had a lot of practice with JavaScript's functional parts, such as built-in array functions. Let's do a challenge. The challenge here to make sure you really understand how mapping works is to recreate the array_map function. Specifically, what we want to create is a function called map that takes two arguments. A function that should be applied to every element in the array, and the array itself. And note here that in this challenge we're ignoring the fact that the regular array_map function can take more than one array at a time. We're only going to worry about the case where we need to map a single array here. So your task here is to recreate the functionality of PHP's array_map function, obviously without actually using the built-in array_map function, since that would be cheating. The easier solution to this problem is to use a for loop, and the slightly…

Contents