0
下面的代碼或多或少是我的代碼塊。 $servername
和$monthlyincome
變量實際上並不是靜態的,但我改變了它們,所以我可以在這裏添加更少的代碼。不能使用字符串偏移作爲數組(這是什麼意思?)
如果我運行此代碼...
$servername="Server1";
$months = array('January','February','March','April','May','June','July','August','September','October','November','December');
for ($i=0;$i<=24;$i++) {
$new_time = mktime(0,0,0,date("m")+$i,1,date("Y"));
$months_array[date("Y",$new_time)][date("m",$new_time)] = "x";
}
$overallincome = 0;
foreach ($months_array AS $year=>$month) {
foreach ($month AS $mon=>$x) {
$monthlyincome = 3;
$overallincome += $monthlyincome;
$$servername[$months[$mon-1]." ".$year]['monthlyincome']=$monthlyincome;
$$servername[$months[$mon-1]." ".$year]['overallincome']=$overallincome;
}
}
我得到這個錯誤...
不能行123
123線使用字符串數組偏移是這條線...... $$servername[$months[$mon-1]." ".$year]['monthlyincome']=$monthlyincome;
我想不出什麼我做錯了。我已經檢查過與其他同樣錯誤的帖子,但沒有任何意義。
'$$ servername []'可能是問題。它可能在'$ {$ servername []}'中解釋它,你想把它解釋爲'$ {$ servername} []'。嘗試將那些花括號放在那裏,看看是否有幫助。 – 2013-05-06 15:39:32
我跑了喬的建議,它似乎解決了你的錯誤。 – abathur 2013-05-06 15:45:23
它修復了它 - 謝謝! 我有一個類似的問題,進一步下來不完全相同的代碼,但我現在正在玩它,看看我是否也可以弄明白。 – 2013-05-06 15:50:53