Notice: Undefined offset 的解决方法
Notice: Undefined offset: 1 in D:\wwwroot\wr\askseo\404.php on line 5
Notice: Undefined offset: 2 in D:\wwwroot\wr\askseo\404.php on line 5
Notice: Undefined offset: 2 in D:\wwwroot\wr\askseo\404.php on line 7
Notice: Undefined offset: 1 in D:\wwwroot\wr\askseo\404.php on line 12
这问题很常出现在数组中的,程序是能正确地运行下去,但是在屏幕上总会出现这样的提示:Notice: Undefined offset: ….. 网上普遍是采用抑制其显示的方法,即更改php.ini文件中error_repoting的参数为”EALL & Notice “,这样屏幕就能正常显示了.
问题是解决了,但是总想不透offset:接下去的数字(如 Notice: Undefined offset: 4 ….)是什么意思.还有,句子里的语法明明是正确的,为什么会出现警告.冷静地思考了好几遍并尝试了每种可能,终于找到了答案.offset:接下去的数字是出错的数组下标,一般是超出了数组的取值范围,如定义了数组$A[]有10个元数,如果出现了$A[10]就会出现错误(Notice: Undefined offset: 10 ….),因为数组的下标是从0开始的,所以这个数组的下标就只能是0~9.因此在出现这类问题时,不要急于用抑制显示的方法(更简单的可以在当前文件的最前面加上一句”error_reporting(填offset:接下去的那个数字);,一定要注意你所用的数组下标,仔细思考一下,问题一定会很快得到解决的 !发也有可能是unset数组后再尝试读取其内容,php手册中有:
Just to confirm, USING UNSET CAN DESTROY AN ENTIRE ARRAY. I couldn’t find reference to this anywhere so I decided to write this.
The difference between using unset and using $myarray=array(); to unset is that obviously the array will just be overwritten and will still exist.
<?php
$myarray=array(“Hello”,”World”);
echo $myarray[0].$myarray[1];
unset($myarray);
//$myarray=array();
echo $myarray[0].$myarray[1];
echo $myarray;
?>
Output with unset is:
<?
HelloWorld
Notice: Undefined offset: 0 in C:webpagesdainsidermyarray.php on line 10
Notice: Undefined offset: 1 in C:webpagesdainsidermyarray.php on line 10
Output with $myarray=array(); is:
?>
<?
HelloWorld
Notice: Undefined offset: 0 in C:webpagesdainsidermyarray.php on line 10
Notice: Undefined offset: 1 in C:webpagesdainsidermyarray.php on line 10
Array
?>
原文地址http://hi.baidu.com/putijie/item/04190dde206bd913e1f46fa9
其实在报错的那一行前面加一个@符号,屏蔽错误就ok了。非常简单。
Notice: Undefined offset 的解决方法的更多相关文章
- Z-BlogPHP 安装出现 (8) Undefined offset: 6 解决方法
有些cp面板的空间会在每个网页头部和页脚增加两个调用的文件,导致zblogPHP安装出错:(8) Undefined offset: 6 主要国外的主机中PHP配置文件两个选项auto_prepend ...
- PHP LINUX Notice: undefined $_GET完美解决方法
PHP Notice: undefined 平时用$_GET[‘xx’] 取得参数值时,如果之前不加判断在未传进参数时会出现这样的警告: PHP Notice: undefined index xxx ...
- PHP获取表单并使用数组存储 疯狂提示 Notice: Undefined offset
$answer=array(); $answer[0]='0'; for($i=1;$i<=$QUESTION_COUNT;$i++){ $answer[$i]=$_POST[(string)$ ...
- [转载][jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
参考 [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法 ---------------------------------------- ...
- [jQuery1.9]Cannot read property ‘msie’ of undefined错误的解决方法
原文:[jQuery1.9]Cannot read property 'msie' of undefined错误的解决方法 $.browser在jQuery1.9里被删除了,所以项目的js代码里用到$ ...
- LaTex: Undefined citation warnings 解决方法
参考 Undefined citations LaTex: Undefined citation warnings 解决方法 在使用TexMaker编译文献的时候,出现引用参考文献的问题: Packa ...
- Linux下Python3.5使用pyqt5.11报错 ImportError: /usr/local/lib/python3.5/dist-packages/PyQt5/QtCore.so: undefined symbol: PySlice_AdjustIndices 解决方法
我用的Linux自带的是Python3.5版本,运行pip3 install PyQt5, 下载的是PyQt5.11,运行PyQt5程序会报错: ImportError: /usr/local/lib ...
- php中提示Undefined index的解决方法
我们经常接收表单POST过来的数据时报Undefined index错误,如下: $act=$_POST['action']; 用以上代码总是提示 Notice: Undefined index: a ...
- Call to undefined function curl_init()解决方法
今天在使用php中的 curl 扩展时 在开启
随机推荐
- 开班典礼-老师玩命的教,大家玩命的学,沉静,18K
接下来的四个月决定我的命运,三年前决定现在,现在决定三年后.喜讯,双元安卓四期,1368$,到第二期仍然不成熟,打分意见多写, 孙健:15011386618 喊出你 的目标.自己监督不了自己,别人可能 ...
- Segmentation
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION There is another way ...
- Rochester Memory Hardware Error Research Project
http://www.cs.rochester.edu/research/os/memerror/
- 浅谈 举家搬迁静态文件到CDN
由于七牛CDN最近做活动,对于标准用户可以免费使用如下优惠 10 GB 存储空间 10 G/月 下载流量 10 万次/月 PUT/DELETE 请求 100 万次/月 GET 请求 以上这些指标直接就 ...
- php四个常用类封装 :MySQL类、 分页类、缩略图类、上传类;;分页例子;
Mysql类 <?php /** * Mysql类 */ class Mysql{ private static $link = null;//数据库连接 /** * 私有的构造方法 */ pr ...
- LINQ延迟查询的例子
//linq延迟查询.两次查询结果不同 List<string> l = new List<string>() { "aaa", "bbb&quo ...
- 已禁用对分布式事务管理器(MSDTC)的网络访问。请使用组件服务管理工具启用 DTC 以便在 MSDTC 安全配置中进行网络访问。
今天写ASP.NET程序,在网页后台的c#代码里写了个事务,事务内部对一张表进行批量插入,对另外一张表进行查询与批量插入. 结果第二张表查询后foreach迭代操作时报错:已禁用对分布式事务管理器(M ...
- 通过驱动向打印机发送一段(ESC)控制指令
这个功能看起来挺奇葩的, 写这个是因为有客户在使用驱动连接票据打印机, 但是又要开钱箱, 驱动里只能每张单据都开钱箱, 而这个打印机又不是只打印结帐单 所以就需要用软件控制打印机开钱箱 票据打印机一般 ...
- zepto源码--matches--学习笔记
zepto的第一个函数,zepto.matches: 作用:用来匹配dom元素是否匹配某css selector. 它为后面的一些高级方法的实现提供了基础支持,比如事件代理,parent, close ...
- 如何做好多语言(小语种)网站SEO
摘自http://www.life-cream.com/how-to-do-multi-language-seo/ 这篇文章在今年4月就开了头,一直到今天才把坑填好,我是有多懒.在动笔之前本来有个前缀 ...