Call to undefined function each()

Description

each() used to be a PHP native function. It was deprecated in PHP 7.4, and is undefined since PHP 8.0.

Example

<?php

$array = ['a', 'b'];
while(list($key, $value) = each($array)) {
    print "$key => $value\n";
}

?>

Solutions

  • Downgrade to PHP 7.x.

  • Use yield.

  • Use yield from.

  • Use foreach().