當運行以下代碼時,一切正常,直到$ i = 5。之後,我得到了未初始化的字符串偏移量通知,即使數組似乎正在正確填充。我在本地運行時收到此通知,但在遠程服務器上檢查時未收到此通知。兩者都運行v5.2.11。基於錯誤報告配置,我假設輸出不同於本地到遠程,但是是什麼導致了通知?使用變量變量時未初始化的字符串偏移量通知
代碼:
$i = 0;
$row = 0;
$col = 0;
$quad = 0;
while(count($ripDigits) > 0)
{
$ranNum = rand(0, count($ripDigits) - 1);
$ripDigit_splice = array_splice($ripDigits, $ranNum, 1);
$ranDigit = $ripDigit_splice[0];
echo ("\$i = " . $i . " | count(\$ripDigits) = " . count($ripDigits) . "<br />\n");
$thisRow = "row_" . $row;
$$thisRow[$i] = $ranDigit;
echo ("\t\t<td><b>" . $$thisRow[$i] . "</b></td>\n");
$thisUsedColumn = "usedDigits_column_" . $i;
$$thisUsedColumn[$col] = $$thisRow[$i];
$thisUsedColumn = "usedDigits_quad_" . $i;
$$thisUsedColumn[$quad] = $$thisRow[$i];
$i++;
}
輸出:
$i = 0 | count($ripDigits) = 8
$i = 1 | count($ripDigits) = 7
$i = 2 | count($ripDigits) = 6
$i = 3 | count($ripDigits) = 5
$i = 4 | count($ripDigits) = 4
$i = 5 | count($ripDigits) = 3
Notice: Uninitialized string offset: 5 in script.php on line 97
Notice: Uninitialized string offset: 5 in script.php on line 99
Notice: Uninitialized string offset: 5 in script.php on line 102
Notice: Uninitialized string offset: 5 in script.php on line 105
$i = 6 | count($ripDigits) = 2
Notice: Uninitialized string offset: 6 in script.php on line 97
Notice: Uninitialized string offset: 6 in script.php on line 99
Notice: Uninitialized string offset: 6 in script.php on line 102
Notice: Uninitialized string offset: 6 in script.php on line 105
$i = 7 | count($ripDigits) = 1
Notice: Uninitialized string offset: 7 in script.php on line 97
Notice: Uninitialized string offset: 7 in script.php on line 99
Notice: Uninitialized string offset: 7 in script.php on line 102
Notice: Uninitialized string offset: 7 in script.php on line 105
$i = 8 | count($ripDigits) = 0
Notice: Uninitialized string offset: 8 in script.php on line 97
Notice: Uninitialized string offset: 8 in script.php on line 99
Notice: Uninitialized string offset: 8 in script.php on line 102
Notice: Uninitialized string offset: 8 in script.php on line 105
1 8 4 2 7 5 9 3 6
提前感謝!
什麼是ripDigits? – user187291 2010-02-17 13:46:13