It often happens to me to handle data that can be either an array or a null variable and to feed some foreach with these data.
foreach
$values = get_val
More concise extension of @Kris's code
function secure_iterable($var) { return is_iterable($var) ? $var : array(); } foreach (secure_iterable($values) as $value) { //do stuff... }
especially for using inside template code
...