php list() 貌似不支持k=>v呢?

来源:4-4 异常处理-错误字典、TryCatch的集中捕获

慕标3075454

2017-08-09

测试代码:

$a= null;

$b= null;

list($a,$b) = array("1","2");

返回:

$a=1;

$b=2;


测试代码:

$a= null;

$b= null;

list($a,$b) = array("errno"=>"1002","errmsg"=>"123");

返回:

$a=null;

$b=null;


报错信息:

Notice: Undefined offset



写回答

2回答

hong泓零食店

2017-09-21

我也遇到这个问题。知道有没有更优的解决方案

0
1
ColorfulC
list() 仅能用于数字索引的数组,并假定数字索引从 0 开始。 可以使用索引数组定义get()方法的返回值
2018-02-17
共1条回复

慕标3075454

提问者

2017-08-09

我的php版本是7.0.12

有可能是php版本问题。


解决办法:

使用:array_values()

返回数组中所有的值。


list(self::$errno,self::$errmsg) = array_values(Err_Map::get(1005));

0
0

高性能的PHP API接口开发

掌握核心API接口开发及性能调优,让你的代码运行效率加倍

1044 学习 · 149 问题

查看课程