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

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

Last modified: 16 May 2022

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

The array_filter (php.net) function is used for filtering array elements by using a callback function. You can also use a foreach loop (php.net) to achieve the same result.

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