2014-01-13 66 views
0

如何解決這個未定義的偏移量錯誤。php - 未定義的偏移量

我得到:234Undefined offset 0 - 44, on line 234.

行看起來是這樣的:

$mysql['invo_mysql_where'] .= ($x > 0 ? " OR " : '')."`id` = {$mysql['inactive'][$x]}"; 

代碼的整個部分,看起來是這樣的:

shuffle($mysql['inactive']); 
     for($x = 0, $l = $mysql['inactive_amount']; $x < $l; $x++){ 
      $mysql['invo_mysql_where'] .= ($x > 0 ? " OR " : '')."`id` = {$mysql['inactive'][$x]}"; 
     } 

$mysql_inactive

$mysql['inactive'] = array(); 
     if($ile == 10){ 
      $mysql['inactive_amount'] = mt_rand(0, 1); 
     } else if($ile == 20){ 
      $mysql['inactive_amount'] = mt_rand(0, 2); 
     } else if($ile == 30){ 
      $mysql['inactive_amount'] = mt_rand(0, 3); 
     } else if($ile == 40){ 
      $mysql['inactive_amount'] = mt_rand(0, 4); 
     } else if($ile == 50){ 
      $mysql['inactive_amount'] = mt_rand(0, 4); 
     } else if($ile == 60){ 
      $mysql['inactive_amount'] = mt_rand(1, 3); 
     } else if($ile == 70){ 
      $mysql['inactive_amount'] = mt_rand(2, 3); 
     } else if($ile == 80){ 
      $mysql['inactive_amount'] = mt_rand(3, 4); 
     } else if($ile == 90){ 
      $mysql['inactive_amount'] = mt_rand(4, 4); 

     } else if($ile == 100){ 
      $mysql['inactive_amount'] = mt_rand(5, 5); 
     } else if($ile == 200){ 
      $mysql['inactive_amount'] = mt_rand(6, 5); 
     } else { 
      $mysql['inactive_amount'] = mt_rand(20, 50); 
     } 
     $mysql['invo_mysql_where'] = ''; 
+0

什麼是'$ mysql ['inactive']'?看起來它不是一個數組,或者它是空的。 – BenM

+0

再次檢查我的問題;我已經更新它並添加了$ mysql ['inactive']; – oliverbj

+0

這是一個空白的數組,但你試圖訪問索引? – BenM

回答

0

的問題是,你定義$mysql['inactive']爲空數組這裏:

$mysql['inactive'] = array(); 

然後再也元素添加到它。後來,您嘗試使用它作爲這裏人口密集陣:因爲沒有索引的$mysql['inactive']數組定義發生

$mysql['inactive'][$x] 

錯誤。爲了解決這個問題,你需要用一些數據填充它。