Tuesday, 3 September 2013

Check for variable before foreach loop, shorthand?

Check for variable before foreach loop, shorthand?

I have code set up like the following often:
if ($arr) {
foreach ($arr as $a) {
// Code stuffs
}
}
If $arr doesn't exist, it doesn't matter in the slightest, so I'm tempted
to use everybody's favorite suppressor (@) rather than muck up my code
with that if statement.
Is there some kind of shorthand to do that if check and foreach on the
same line?
Any huge issue with suppressing the error in this context?

No comments:

Post a Comment