PhpStorm 2020.2 Help

Code Inspection: 'array_fill' can be converted to loop

Reports the array_fill calls that can be replaced with the foreach loop.

The array_fill ( function is used for filling an array with values. You can also use a foreach loop ( to achieve the same result.

In the following example, the myArr array is filled with values by using either the array_fill function call or the foreach loop.

$myArr = array_fill(0, 2, 'foo');
$array_fill = []; for ($i = 0; $i < 2; $i++) { $array_fill[$i] = 'foo'; } $myArr = $array_fill;
Last modified: 08 May 2020