each() Is No More¶
The each function is the base for the while loop that traverse arrays. The modern version of this loop is foreach, which does not rely on each, and improves the loop in speed and reliability. Hence, each was deprecated in PHP 7.4, and removed in 8.0.
PHP code¶
<?php
while(list($k, $v) = each($array)) {
print $k . ' => '. $v.PHP_EOL;
}
?>
Before¶
PHP Deprecated: The each() function is deprecated. This message will be suppressed on further calls
Deprecated: The each() function is deprecated. This message will be suppressed on further calls
PHP Warning: Variable passed to each() is not an array or object
Warning: Variable passed to each() is not an array or object
After¶
PHP Fatal error: Uncaught Error: Call to undefined function each()
Fatal error: Uncaught Error: Call to undefined function each()
PHP version change¶
This behavior was deprecated in 7.4
This behavior changed in 8.0