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
yield
oryield from
call.Use an
iterator
to traverse the array.
In more recent PHP versions, this error message is now Call to undefined function each().