PhpStorm
 
Get PhpStorm
You are viewing the documentation for an earlier version of PhpStorm.

Code Inspection: 'array_map()' call can be converted to loop

Last modified: 16 May 2022

Reports the array_map() calls that can be replaced with foreach loops.

The array_map (php.net) function accepts one or several arrays as arguments, applies a callback function to each of their elements, and returns a new array containing the resulting elements. You can also use a foreach loop (php.net) to achieve the same result.

In the following example, the myArr array's values are doubled by using the odd() callback function. The function is called from either the array_map() function call or the foreach loop.