我完全不知道我现在做错了什么。我觉得我精神疲惫,因为我完全无能为力。以下是我正在使用的代码:为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