Hey guys I’m working on a chunk of my function and trying to keep it a little cleaner
I was trying to use if(each($ar['error']!=0)) intead of running this through a FOREACH
loop but can’t get it to work right. Maybe a second set of eyes on this, and some other thoughts?
This is how it is currently
foreach($ar['error'] as $err) {
if($err!=0) {
switch($err) {
case 1: $this->doDie($this->errors['upl-ini-max']); exit; break;
case 2: $this->doDie($this->errors['upl-maxsize']); exit; break;
case 3: $this->doDie($this->errors['upl-partial']); exit; break;
case 4: $this->doDie($this->errors['upl-no-file']); exit; break;
case 6: $this->doDie($this->errors['upl-no-tmpDir']); exit; break;
case 7: $this->doDie($this->errors['upl-cant-write']); exit; break;
case 8: $this->doDie($this->errors['upl-ext']); exit; break;
}
}
}
and I was trying to do something along the lines of
include('class/debug.class.php');
$ar['error'][3]=1;
if($ar['error']['value']!=0) {
switch($ar['error']['value']) {
case 1: $this->doDie($this->errors['upl-ini-max']); exit; break;
case 2: $this->doDie($this->errors['upl-maxsize']); exit; break;
case 3: $this->doDie($this->errors['upl-partial']); exit; break;
case 4: $this->doDie($this->errors['upl-no-file']); exit; break;
case 6: $this->doDie($this->errors['upl-no-tmpDir']); exit; break;
case 7: $this->doDie($this->errors['upl-cant-write']); exit; break;
case 8: $this->doDie($this->errors['upl-ext']); exit; break;
}
}
debug($ar);
//debug
'error' =>
array (
0 => 0,
1 => 0,
2 => 0,
3 => 1,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
),
But it seems like it never catches the 1?
If you are traversing an array with
each()this is typically done in combination with thelist()function within a while loop. So if you are trying to avoid theforeach()loop, this is the other possibility.Check out the documentation for
each()http://php.net/manual/en/function.each.php