不推荐使用 each() 函数。此消息将在进一步调用 PHP 7.2 时被抑制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51278484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:52:11  来源:igfitidea点击:

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

php

提问by BBT

I have the below each()line in a PHP file on a server where I recently upgraded the PHP version from 5 to 7.

each()最近将 PHP 版本从 5 升级到 7 的服务器上的 PHP 文件中有以下行。

while(list($file, $info) = each($this->images))

The error below is thrown by the web server after the restart.

重新启动后,Web 服务器抛出以下错误。

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

each()功能已弃用。此消息将在进一步调用时被抑制

What will be the correct way of re-writing the above line of code in PHP 7.2?

在 PHP 7.2 中重写上述代码行的正确方法是什么?

Thank you.

谢谢你。

回答by Progrock

You should be able to swap out your eachfor a foreachin the most part.

你应该能够换出你的一个的foreach中的大部分。

<?php

foreach($this->images as $file => $info) {
    // ...
}