您现在的位置是: 首页 > 后端开发 PHP 中list()出现Undefined offset: 0错误
PHP 中list()出现Undefined offset: 0错误
2020-05-20 【后端开发】 3560人已围观 6610次浏览
简介PHP 中list()出现Undefined offset: 0错误
在PHP中,list()主要用于在一次操作中,给一组变量赋值
比如:
$my_array = array('Dog','Cat','Horse');
list($a, $b, $c) = $my_array;
echo 'I have several animals, a '.$a.', a '.$b.' and a '.$c;
?>
正常输出,结果如下
I have several animals,a Dog,a Cat and a Horse.
但是,当数组不是数字数组,而是关联数组时,如
list($a,$b) = array('errno' => 0, 'errmsg' => "undefined");
结果就会报错,提示下面这样类似的错误
Notice: Undefined offset:0 in XXXXXX on line 1
出现这样的错误,就是因为list是从0开始索引数组,而不是通过关联数组来索引
当上面的代码修改为
list($a,$b) = array(0 => 0, 1 => "undefined");
就可以正常输出,但是当代码为
list($a,$b) = array(1 => 0, 2 => "undefined");
同样的,也是会提示下面类似的错误
Notice: Undefined offset:0 in XXXXXX on line 1
变量$a并没有被赋值,下标为1的元素给了变量@b,下标为0的元素并没有定义,导致$a为空,出现上面的错误提示。而下标为2的元素,没有赋值对象,留空
很赞哦! (0)
相关文章
- SqlServer字符串处理
- 记一次Java MessageFormat.format踩坑
- Nestedset 出现 Node must exists. 错误解决方案
- SqlServer 刷新所有视图
- RocketMQ 出现 sendDefaultImpl call timeout 问题
- SqlServer 优化技巧
- SpringBoot 启动测试时出现提示 Test class should have exactly one public zero-argument constructor
- 删除Git仓库所有历史提交记录,成为一个干净的仓库
- 类 BASE64Decoder 程序包 sun.misc 找不到符号
- SqlServer 查询包含指定字段的存储过程
点击排行
- Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR DISABLE You can't write or read against a disable instance
- RocketMQ 出现 sendDefaultImpl call timeout 问题
- Debian apt 使用国内镜像
- 类 BASE64Decoder 程序包 sun.misc 找不到符号
- SpringBoot @NotBlank 不生效问题
- 记一次 Mybatis-Plus 自动填充无效问题解决
- nuxt 项目完整部署方案
- SpringBoot 2.x 文件上传出现 The field file exceeds its maximum permitted size of 1048576 bytes
站长推荐
猜你喜欢
- Nestedset 出现 Node must exists. 错误解决方案
- 迁移 Docker 目录
- Chrome 谷歌浏览器清除HTTPS证书缓存
- Oracle ORA-12541:TNS:no listener错误解决方法
- 在使用Flutter进行网络请求时,使用Dio访问https地址出现unable to get local issuer certificate错误
- SqlServer字符串处理
- ElasticSearch安装踩坑指南
- Linux 查看磁盘、磁盘分区、挂载磁盘、卸载磁盘操作
- gulp3 在 node12 上运行出现异常 primordials is not defined
- SpringBoot 定时任务 多线程