php技术博客
让天下没有搞不定的bug~

php报Undefined offset错误的解决办法

今天小涛写while循环时,遇到了这个错误:Notice: Undefined offset: 8 in D:\wwwRoot\company\5\1.php

$fp = fopen($log, “r+”);

while (($line = fgets($fp)) !== false)

{

if (strpos($line, ‘Baiduspider’) !== false)

{

preg_match($baidu_preg, $line, $matches);

$hour = intval(substr($matches[‘1’], -8, -6));

$baiduspider[$hour]++;

}

}

 

提示

$baiduspider[$hour]++;

出现错误,原来是因为数组中没有下标为1的项. php中数组第一个元素的下标为0,不过对程序运行的结果没有影响,
设置下报错级别就可以了,在头部加上  error_reporting(0);

技术分享,技术交流,小涛与您共同成长……

赞(0)
未经允许不得转载:PHP技术博客 » php报Undefined offset错误的解决办法