2010-02-17 3 views
1

다음 코드를 실행하면 $ i = 5까지 모든 것이 잘 작동합니다. 배열에 올바르게 채워지는 것처럼 보이지만 초기화되지 않은 문자열 오프셋 알림이 표시됩니다. 로컬 서버에서 실행될 때이 알림을 받지만 원격 서버에서 확인하지는 않습니다. 둘 다 v5.2.11을 실행 중입니다. 출력이 configs 오류보고를 기반으로 로컬에서 원격으로 다를 것이라고 가정합니다. 그러나 통지의 원인은 무엇입니까?가변 변수를 사용할 때 초기화되지 않은 문자열 오프셋 알림

코드 :

$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 

감사합니다!

+0

ripDigits 란 무엇입니까? – user187291

답변

0

좋아,이게 무슨 목적인지 모르겠지만 말하기는 어렵다.하지만 변수 변수에 중괄호를 써서 해결할 수 있을지는 의심된다. 변수 이름으로 $ thisRow [$ i]를 사용하려하지만 존재하지 않습니다.

$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++; 
} 

ripDigits가 6 개의 숫자 배열로 초기화되면서 효과적입니다.

또한 서버에서 '작동'하는 이유는 오류보고 (E_NOTICE)가 해제 된 것일 수 있습니다.

+0

감사합니다. 나는 그것을 조금 후에 시도 할 것이다. 전에 중괄호를 사용했지만 {$$ thisRow} (으)로했습니다. 루프로 돌아가서 여기에 결과를 업데이트 할 것입니다. 오류보고에 동의합니다. – Eric

1

귀하의 서버와 로컬 컴퓨터의 PHP 버전이 다를 것 같아요. 오늘 나는이 메시지를 받았다. xammp v.1.7.4를 사용하면이 메시지를 얻는다.하지만 1.7.3을 사용하면 그렇지 않다.

관련 문제