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
If you're using php7 and you want to handle only undefined errors this is the cleanest IMHO
$array = [1,2,3,4]; foreach ( $array ?? [] as $item ) { echo $item; }