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.
Mapping
- [Instructor] The next functional operation we're going to be talking about for working with arrays is called mapping. And to do it, we'll be making use of one of PHP's built-in array functions, a function called array map. So quite often, it happens that we have an array of data and we want to convert each of the individual elements in the array to some other form. For example, we might have an array of numbers and we want to double all the numbers in the array. Or we might want to convert an array of inch measurements into an array of centimeter measurements. Or we might have an array of person objects with name, age, and job attributes, and maybe a lot more data as well, and we want to convert this data into an array that contains only the people's names. The typical way of doing this, and the way that many of us first learn how to do it was to use a for loop and an index variable to loop through all the elements in…
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
-
-
-
-