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