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 - PHP Tutorial
From the course: Functional Programming with PHP
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Working with arrays, functionally1m 42s
-
(Locked)
The spread operator and array_merge7m 37s
-
(Locked)
Mapping4m 46s
-
(Locked)
Filtering4m 58s
-
(Locked)
Passing keys to array functions4m 21s
-
(Locked)
Sorting3m 39s
-
(Locked)
Custom sorting behavior with usort6m 27s
-
(Locked)
Reducing6m 10s
-
(Locked)
Combining array functions6m 50s
-
(Locked)
Challenge: Recreating the array_map function1m 6s
-
(Locked)
Solution: Recreating the array_map function3m 40s
-
-
-
-