Undefined offset error
을받는 이유는 무엇입니까? 배열의 각 요소에 10,20,20
을 추가하려고합니다. 도와주세요. 미리 감사드립니다정의되지 않은 오프셋 오류가 발생했습니다.
<?php
$arr = array("a","b","c");
$counter = 0;
$status = array();
foreach($arr as $a){
$status[$counter] += 10;
$status[$counter] += 20;
$status[$counter] += 20;
echo $status[$counter]."<br>";
$counter ++;
}
?>
오류 :
Notice: Undefined offset: 0 in C:\xampp\htdocs\test\index.php on line 6
300
Notice: Undefined offset: 1 in C:\xampp\htdocs\test\index.php on line 6
300
Notice: Undefined offset: 2 in C:\xampp\htdocs\test\index.php on line 6
300
코드에서
`
왜'$ status [$ counter] + = 50;가 아닌가? –
@Jack, Idk 왜'$ counter'가 필요한지,'key' 자체를 사용할 수 없습니까? 꽤 불분명 한 질문. –
@ShankarDamodaran 잘 모르겠습니다 :) –