With PHP 7.2, each
is deprecated. The documentation says:
Warning This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.
How can I update my code to avoid using it? Here are some examples:
-
$ar = $o->me; reset($ar); list($typ, $val) = each($ar);
-
$out = array('me' => array(), 'mytype' => 2, '_php_class' => null); $expected = each($out);
-
for(reset($broken);$kv = each($broken);) {...}
-
list(, $this->result) = each($this->cache_data);
-
// iterating to the end of an array or a limit > the length of the array $i = 0; reset($array); while( (list($id, $item) = each($array)) || $i < 30 ) { // code $i++; }
When I execute the code on PHP 7.2 I receive the following error:
Deprecated: The each() function is deprecated. This message will be suppressed on further calls
foreach()
– Cuprousarray_map()
with a closure would also work. – Corrody