PHP Notice: Undefined offset: 1
這裏是PHP代碼,拋出它:
$file_handle = fopen($path."/Summary/data.txt","r"); //open text file
$data = array(); // create new array map
while (!feof($file_handle)) {
$line_of_text = fgets($file_handle); // read in each line
$parts = array_map('trim', explode(':', $line_of_text, 2));
// separates line_of_text by ':' trim strings for extra space
$data[$parts[0]] = $parts[1];
// map the resulting parts into array
//$results('NAME_BEFORE_:') = VALUE_AFTER_:
}
這個錯誤是什麼意思不確定的偏移?什麼導致這個錯誤?
你是如何確定文件中的每一行都有冒號? – andrewsi
做'var_dump($ parts)'。你可能會發現,你得到那個未定義的偏移量,零件數組中沒有'1'鍵。 –
如果看起來所有行都有冒號,請檢查空行。 – Barmar