您能否幫助您瞭解爲什麼值未分配給數組元素?數組未分配值
我陣列的print_r是這樣的:
Array ([0] => Array ([month] => May [year] => 2014 [count] => 0) [1] => Array ([month] => Apr [year] => 2014 [count] => 0) [2] => Array ([month] => Mar [year] => 2014 [count] => 0) [3] => Array ([month] => Feb [year] => 2014 [count] => 0) [4] => Array ([month] => Jan [year] => 2014 [count] => 0) [5] => Array ([month] => Dec [year] => 2013 [count] => 0) [6] => Array ([month] => Nov [year] => 2013 [count] => 0) [7] => Array ([month] => Oct [year] => 2013 [count] => 0) [8] => Array ([month] => Sep [year] => 2013 [count] => 0) [9] => Array ([month] => Aug [year] => 2013 [count] => 0) [10] => Array ([month] => Jul [year] => 2013 [count] => 0) [11] => Array ([month] => Jun [year] => 2013 [count] => 0))
我有一些代碼,應該添加一個值來算。
foreach($archives as $archive){
if ($archive['month'] == date('M', strtotime($post['timestamp']))){
echo 'hello';
$archive['count']++;
}
}
'hello'被輸出,但count並不會收到該值。我也試過這個,但沒有奏效。
$archive['count'] = 'hello';
感謝您的幫助。
很好,謝謝。 – Andrew
[非常小心循環中的指針!爲了安全起見,你應該在循環中取消設置($ archive)'](http://www.php.net/manual/en/control-structures.foreach.php) – Rudie