国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Notice: Undefined offset 的解決方法

2019-11-15 02:13:07
字體:
來源:轉載
供稿:網友
Notice: Undefined offset 的解決方法

調試程序的時候總是出現錯誤提示:

Notice: Undefined offset: 1 in xxx.phpon line48Notice: Undefined offset: 2 inxxx.phpon line48

Notice: Undefined offset: 3 inxxx.phpon line48

Notice: Undefined offset: 4 inxxx.phpon line48

這問題很常出現在數組中的,程序是能正確地運行下去,但是在屏幕上總會出現這樣的提示: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:<?HelloWorldNotice: Undefined offset: 0 in C:webpagesdainsidermyarray.php on line 10Notice: Undefined offset: 1 in C:webpagesdainsidermyarray.php on line 10Output with $myarray=array(); is:?><?HelloWorldNotice: Undefined offset: 0 in C:webpagesdainsidermyarray.php on line 10Notice: Undefined offset: 1 in C:webpagesdainsidermyarray.php on line 10Array

?>

這就是問題的根本原因了。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嵊州市| 金沙县| 临沧市| 乌什县| 永福县| 上杭县| 彰化县| 诸城市| 宁晋县| 罗源县| 乐陵市| 双流县| 开封县| 义乌市| 鹿泉市| 大方县| 永昌县| 长宁区| 射阳县| 玛沁县| 利川市| 宁河县| 浮山县| 太和县| 耒阳市| 威信县| 泽库县| 克拉玛依市| 云梦县| 普宁市| 盈江县| 衢州市| 西盟| SHOW| 炉霍县| 福州市| 舞钢市| 辰溪县| 申扎县| 寻甸| 敦煌市|