我想返回一個數組。數組鍵是年份,數組值也是如此。爲什麼我不斷收到「未定義的偏移量」消息?
但是,當我在while循環中設置數組鍵時,它一直給我一個「未定義的偏移量」。
我不明白未定義的偏置集是什麼,當我清楚地迴應變量的值並顯示所有年份時。
以下是我的方法。任何幫助將非常感激。謝謝!
private function list_of_yrs(){
$start = 2005;
$end = date("Y");
$output = array();
$output[-1] = "Please select a year";
while($start <= $end){
$key_and_val = $start++;
$output[$key_and_val] .= $key_and_val;
}
return $output;
}
你永遠不會初始化自己的價值觀。你將一個字符串連接成未定義的。 – Rizier123
[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – andrewsi