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
How about this solution:
$type = gettype($your_iteratable); $types = array( 'array', 'object' ); if (in_array($type, $types)) { // foreach code comes here }