2014-04-22 38 views
-2

if語句我在下面的代碼是給我下面的錯誤:構建比賽現場

Notice: Undefined offset: 1 in C:\xampp\htdocs\Project4\matches-submit.php on line 31

我已經嘗試每一個可能性,我無法找出錯誤。

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]); 
+1

在約會網站上有一個'undefined offset'有趣的東西:) –

+0

在試圖使用它之前,檢查是否設置了'$ information [1]'。爲此,使用'isset()'。 –

+0

很多在你的代碼中丟失的括號 –

回答

1

首先檢查是否$信息有條目:

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

你必須檢查是否有在數組中的偏移信息1,如果不是你會得到你看

錯誤
+0

謝謝,現在可以使用 – user3513160