我完全不知道我現在做錯了什麼。我覺得我精神疲憊,因爲我完全無能爲力。以下是我正在使用的代碼:爲foreach提供的參數無效()
if(empty($this->updates) || !is_array($this->updates))
return null;
foreach($this->updates as $update)
這是失敗的。但是,如果我在foreach之前(和之後)執行print_r($ this-> updates),那麼它工作得很好。爲什麼當我嘗試在foreach中使用它時,它假裝數組不存在?
樣品的print_r($這個 - >更新):
Array
(
[0] = Array
(
[id] => 1
[name] => test
)
[1] = Array
(
[id] => 2
[name] => rawr
)
)
如果您嘗試將*數組以外的任何事物*傳遞給'foreach',通常會發生此錯誤。你的'print_r'返回了什麼? – 2010-09-28 13:12:59
我們可以看到'print_r'的結果嗎? – fredley 2010-09-28 13:13:02
你能告訴使用var_dump($ this-> updates)的結果嗎?另外,你應該添加if(!isset($ this-> updates)|| empty($ this-> updates)) – Shikiryu 2010-09-28 13:14:19