如何在正则表达式中修复此错误“ Undefined offset:”?

时间:2019-03-21 12:57:27

标签: php regex

对于数据中的每一行,我都会收到此错误。因此大约有500次,但每次都有另一个未定义的偏移量。 这是我的代码:

$fl_array = preg_grep('/^\d+\s('. $SelectedTime .':)\d+/', explode("\n", $finalLog));
$count = count($fl_array);

for ($x = 0; $x < $count; $x++)
{
    echo "$fl_array[$x] \n";
}

1 个答案:

答案 0 :(得分:0)

如此处所写-http://php.net/manual/en/function.preg-grep.phpReturns an array indexed using the keys from the input array.,所以您的按键可能有误:

if (isset($fl_array[$x])) {
    echo "$fl_array[$x] \n";
}
相关问题