Php PDO::fetchAll索引上的未定义索引警告
我花了很长时间试图找出原因,因为“未定义索引”警告有很多不同的潜在原因 行Php PDO::fetchAll索引上的未定义索引警告,php,mysql,pdo,indexing,undefined,Php,Mysql,Pdo,Indexing,Undefined,我花了很长时间试图找出原因,因为“未定义索引”警告有很多不同的潜在原因 行$singleresult=$result[0]是第71行。我肯定设置了$result[0],因为我已经用print\r和isset检查对其进行了验证。我错过什么了吗?我有点希望我只需要在这里做一次精神检查。:) 您的变量未设置,您不会注意到,因为您的if行错误: if (isset($result[0]) && isset($result[1])); {
$singleresult=$result[0]代码>是第71行。我肯定设置了$result[0]
,因为我已经用print\r
和isset
检查对其进行了验证。我错过什么了吗?我有点希望我只需要在这里做一次精神检查。:)
您的变量未设置,您不会注意到,因为您的if
行错误:
if (isset($result[0]) && isset($result[1])); {
^ your problem
$singleresult = $result[0];
return $singleresult;
}
同:
if (isset($result[0]) && isset($result[1])) {
}
$singleresult = $result[0];
return $singleresult;
因为代码>您在您的条件后添加。只需将其移除,结果就应该是您期望的结果:
if (isset($result[0]) && isset($result[1])) {
if (isset($result[0]) && isset($result[1])) {
}
$singleresult = $result[0];
return $singleresult;
if (isset($result[0]) && isset($result[1])) {