这些是我得到的错误
(!)注意:未定义的偏移量:第35行的C:\ wamp64 \ www \ searches.php中的1 调用堆栈
(!)注意:未定义的偏移量:第35行的C:\ wamp64 \ www \ searches.php中的2
(!)注意:未定义的偏移量:第42行的C:\ wamp64 \ www \ searches.php中的2
第35行是$totalSum = $totalSum + $amYearNumbers[1][$x];
这是整个for循环的一部分
preg_match_all('/(\d)\s<span>year/', $amItemYEAR, $amYearNumbers);
print_r($amYearNumbers);
if ($amYearNumbers) {
$amYearNumbersLength = count($amYearNumbers);
$totalSum = 0;
for ($x = 0; $x <= $amYearNumbersLength ; $x++) {
$totalSum = $totalSum + $amYearNumbers[1][$x];
}
}
print_r($amYearNumbers);
返回
数组([0] =&gt;数组([0] =&gt; 8年)[1] =&gt;数组([0] =&gt; 8))
我确定错误的确切含义,我只想将所有返回的数字相加
答案 0 :(得分:1)
检查一下,
if (count($amYearNumbers)) {
$amYearNumbersLength = count($amYearNumbers[0]);
$totalSum = 0;
for ($x = 0; $x < $amYearNumbersLength ; $x++) {
$totalSum = $totalSum + $amYearNumbers[0][$x];
}
}
答案 1 :(得分:0)
if ($amYearNumbers) {
$amYearNumbersLength = count($amYearNumbers);
$totalSum = 0;
for ($x = 0; $x < $amYearNumbersLength ; $x++) {
$totalSum += $amYearNumbers[$x][0];
}
}
答案 2 :(得分:0)
你的计数和循环数不一样。
GenerateEndEntityCertificate