php7.2使用each()报错

PHP / 423人浏览 / 0人评论

The each() function is deprecated. This message will be suppressed on further calls

php7.2使用each()报错

The each() function is deprecated. This message will be suppressed on further calls

php7.2以上版本已经废除了each()方法,项目中用到的地方会出现以下报错。

$fruits[0]["fruit"] = "lemons";
$fruits[1]["fruit"] = "apples";
$fruits[2]["fruit"] = "grapes";

usort($fruits, array('\app\index\controller\Index','cmps'));

while (list($key, $value) = each($fruits)) {
    echo "$fruits[$key]: " . $value["fruit"] . "\n";
}

使用foreach替换while,不使用list函数处理

foreach($fruits as $key=>$value) {
    echo $key.':'.$value["fruit"] . "\n";
}

返回结果

0:apples
1:grapes
2:lemons

转载注明:

0 条评论

还没有人发表评论

发表评论 取消回复

记住我的信息,方便下次评论
有人回复时邮件通知我