The each() function is deprecated. This message will be suppressed on further calls¶
Description¶
The function each was deprecated in PHP 7.x and removed in PHP 8.0. It was mainly used in loops like the above, and could be replaced advantageously with a foreach structure.
Example¶
<?php
$array = ['a', 'b'];
while(list($key, $value) = each($array)) {
print "$key => $value\n";
}
?>
Solutions¶
Replace the while loop with a foreach one.
Replace the loop with a call to one of the array function.
Traverse the array with a
yieldoryield fromcall.Use an
iteratorto traverse the array.
In more recent PHP versions, this error message is now Call to undefined function each().
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See each.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Php/Php72RemovedFunctions.