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

Mapping - PHP Tutorial

From the course: Functional Programming with PHP

Start my 1-month free trial

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…

Contents