Code Inspection: 'array_fill' can be converted to loop
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the array_fill()
calls that can be replaced with foreach
loops.
The array_fill (php.net) function is used for filling an array with values. You can also use a foreach loop (php.net) 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.
array_fill() call
$myArr = array_fill(0, 2, 'foo');
foreach loop
$array_fill = [];for ($i = 0; $i < 2; $i++) { $array_fill[$i] = 'foo';}$myArr = $array_fill;
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.