php deprecated,解决php中each函数在7.2版本提示deprecated错误问题
今天有個thinkphp5.0版本的項目切換到php7.2版本,有個頁面一直報錯,打開調試代碼。發現錯誤提示“
The each() function is deprecated. This message will be suppressed on further calls”。說明php不建議繼續使用each函數了,那如何修改代碼了,下面介紹兩種方法:
1、改成 key()、current()函數來組裝
$arr=['name'=>'phper163','year'=>2020];
list($a,$b)?=?[key($arr),current($arr)];
var_dump($a,$b);//string(4)?"name"?string(8)?"phper163"
2、使用foreach語法來實現
$arr=['name'=>'phper163','year'=>2020];
foreach($arr?as?$key=>$val){
var_dump([$key,$val]);
}
//array(2)?{?[0]=>?string(4)?"name"?[1]=>?string(8)?"phper163"?}?array(2)?{?[0]=>?string(4)?"year"?[1]=>?int(2020)?}
總結
以上是生活随笔為你收集整理的php deprecated,解决php中each函数在7.2版本提示deprecated错误问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Go语言实战(一)环境配置
- 下一篇: 做简单的android 软件推荐,And