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 扩展时 在开启
随机推荐
- B-Tree indexs
mysql_High.Performance.MySQL.3rd.Edition.Mar.2012 A B-Tree index speeds up data access because the s ...
- http响应状态码301和302
HTTP返回码中301与302的区别 (2012-10-15 22:06:09) 一.官方说法 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redir ...
- 【转】全面解析Unity3D自动生成的脚本工程文件
http://blog.csdn.net/jjiss318/article/details/7632041 我们在Unity3D开发的时候,经常会看到它会产生不少固定命名工程文件,诸如: Assemb ...
- [daily][archlinux][pacman] local database 损坏
下午,开心的看着dpdk的文档,做做各种小实验. 后台正常yaourt -Syu,三个多G的下载,我总是过很久才update一次. 然后KDE窗口各种异常,我知道又在开始更x相关的东西了.可是因为X异 ...
- .Net搭建的WebService测试页使用TextArea大文本框方便调试
用.Net搭建的WebService,系统默认提供了测试页,供大家输入参数进行测试.但因为参数输入框使用的是单行input控件,导致无法输入换行文本,使得有些参数(如换行的xml)无法输入,及其不便. ...
- Oracle客户端显示乱码解决
1.查找当前服务器的字符集: 2.使用查询得到的结果集,设置本地local字符集:(不要照抄图片)
- php--yii2.0框架的curl
yii2.0框架的增删改查 //插入操作 save() $customer=new Customer(); $customer->name=‘小熊‘; $customer->save() ...
- Node的Buffer
var buf3 = new Buffer([1,2,3,4,-10,256],'utf8');//默认为utf8 console.log(buf3[0]);//正常的范围是0~255 console ...
- C#中string.Empty ,"" , null 区别
引言 String类型作为使用最频繁的类型之一,相信大家都非常熟悉,对于string赋予空值,通常有以下三种方式: String str1=null; String str2=””; String s ...
- Android.mk学习 笔记
感谢: 原创作品 转载请注明出处:http://www.cnblogs.com/langlang/ 作者email: dayhappyhappy@163.com LOCAL_PATH := $(cal ...