I have absolutely no idea what I’m doing wrong right now. I think I’m mentally exhausted, because I’m utterly clueless. Here’s the code I’m using:
if(empty($this->updates) || !is_array($this->updates))
return null;
foreach($this->updates as $update)
This is failing. HOWEVER, if I do a print_r($this->updates) before the foreach (and after), it works perfectly fine. Why is it that when I try to use it in a foreach it pretends the array doesn’t exist?
Sample print_r($this->updates):
Array
(
[0] = Array
(
[id] => 1
[name] => test
)
[1] = Array
(
[id] => 2
[name] => rawr
)
)
Since you don’t tell what
$this->updatesis, I can simply assume it’s not an array. Here, you have two options :1- Replace
empty()with!is_array()to check if$this->updatesis valid or not. If it’s empty, it doesn’t matter, theforeachwill simply do nothing…Or if the
foreachis not the only processing you do :2- Force
$this->updatesto be an array