在 PHP 7.2 中, each
已弃用。 文档 说:
警告 自 PHP 7.2.0 起,该函数已被弃用。强烈建议不要依赖此功能。
如何更新我的代码以避免使用它?这里有些例子:
- ”` \(ar = \)o->me; reset(\(ar); list(\)typ, \(val) = each(\)ar);
2. ```
$out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
$expected = each($out);
- ”` for(reset(\(broken);\)kv = each($broken);) {…}
4. ```
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++; }
”`
当我在 PHP 7.2 上执行代码时,我收到以下错误:
已弃用:each() 函数已弃用。此消息将在进一步调用时被隐藏
原文由 yokogeri 发布,翻译遵循 CC BY-SA 4.0 许可协议
key()
和current()
来分配您需要的值。}
for (\(i = 0; \)i < 30; \(i++) { \)id = key(\(array); \)item = current(\(array); // code next(\)array); }
”`