PHP 7.2 each()函数已弃用 [英] php 7.2 each() function is deprecated
问题描述
if ( is_array( $u ) ) {
while( list( $key ) = each( $u ) ) {
$u = $u[$key];
break;
}
}
并且我的php版本是7.2 当我在laravel框架上运行它时,我遇到了这个错误
and my php version is 7.2 when i run it on laravel framwork i gat this error
The each() function is deprecated. This message will be suppressed on further calls
我发现多数民众赞成我必须将每个更改为foreach 在此处输入链接描述
i found thats i have to change each to foreach enter link description here
告诉任何人将代码更改给我,以便在php 7.2上工作
cound any one change the code to me to work on php 7.2 thanks
推荐答案
while( list( $key ) = each( $u ) ) {
$u = $u[$key];
break;
}
绝对没有理由在这里进行循环.您只是从数组中获取第一个值并覆盖该数组.可以使用current()在一行中重写上述循环,这会将当前值(如果未更改数组的指针,则为第一个值)从数组中拉出:
There's absolutely no reason to do a loop here. You're just getting the first value out of the array and overwriting the array. The above loop can be rewritten in one line using current() which will pull the current value (first value if the array's pointer hasn't been altered) out of the array:
$u = current($u);
这篇关于PHP 7.2 each()函数已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!