str_getcsv
을 사용하는 동안이 정의되지 않은 오프셋 통지를 없애고 CSV 파일을 읽고 키를 할당하는 데 많은 문제가 있습니다.PHP str_getcsv 가져 오기 정의되지 않은 오프셋
다른 스레드에서 언급 된 isset
과 array_key_exists
을 시도했습니다. isset
은 정의되지 않은 인덱스 사항을 해결했지만 나는 정의되지 않은 오프셋 고지를 제거 할 수 없습니다 : 문제
$file = file("lookup.csv",FILE_SKIP_EMPTY_LINES);
$csv = array_map("str_getcsv",$file, array_fill(0, count($file), ';'));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
$numberOfRows = count($csv);
$numberOfColumns = count(current($csv));
for ($i = 0; $i <= $numberOfRows; $i ++) { // first loop to run thru to find correct sku template name in csv file
if ($csv[$i]['sku'] === $sku) { // if sku matches // Getting Undefined offset on this line
for ($j = 0; $j <= $numberOfColumns; $j++) { // second loop to create variables from header line
${$keys[$j]} = isset($csv[$i][$keys[$j]]) ? $csv[$i][$keys[$j]] : ''; // // Getting 2 Undefined offset notices on this line
}
}
}
CSV 파일 일부 빈 셀을 가지고있다. 그 빈 셀은 유지 될 것입니다 (저는 그것에 대해 아무것도 할 수 없습니다).
누구든지 올바른 방향으로 나를 가리킬 수 있습니까? 어떤 도움이 많이 감사합니다, 감사합니다!
이 $ 파일을 시도 = 파일 ('lookup.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); –