Php 建立比赛场地

Php 建立比赛场地,php,html,Php,Html,下面代码中的if语句给出了以下错误: 注意:第31行C:\xampp\htdocs\Project4\matches-submit.php中未定义的偏移量:1 我已经尝试了每一种可能性,但我找不到错误 for ($i=0;$i<$numberofSingles;$i++) { $information = explode(",",$matches[$i]); //explode every single at time if ($gender==$information[1

下面代码中的if语句给出了以下错误:

注意:第31行C:\xampp\htdocs\Project4\matches-submit.php中未定义的偏移量:1


我已经尝试了每一种可能性,但我找不到错误

for ($i=0;$i<$numberofSingles;$i++)
{
    $information = explode(",",$matches[$i]); //explode every single at time
    if ($gender==$information[1]) { //check for gender,if same bye bye
        unset($matches[$i]); //check for gender
    }
    else if ($information[4]!=$os) { //checks for os type
        unset ($matches[$i]);

对于($i=0;$i首先检查$information是否有条目:

if(!empty($information)&&isset($information[1])&&$gender==$information[1]){.... 

你必须检查数组中偏移量1处是否有信息,如果没有,你将得到你看到的错误

约会网站上未定义的偏移量有点可笑:)在尝试使用它之前,检查是否设置了
$information[1]
。为此,请使用
isset()
。您的代码中有许多缺少的括号“我已经尝试了每一种可能性”@M.chaudhry:不要用您的“更正”修改OP的原始代码。如果你有一个建议的解决方案,那么把它作为一个答案发布。