Invalid argument supplied for foreach() to 'No routes found'

Just wondering if anyone had the code to stop the Invalid argument supplied for foreach() and instead replacing it with ‘No routes found’ when no results are returned.

I used to know the code but forgot it.

Thanks!

How about ->

<?php
if (!$variable)
    {do something if the array is empty}
else
    {do something if the array has data}
?>

I would use:

if(!is_array($variable))
{  
    echo 'No routes found';
    return;
}

Though you can also use

!$variable

I’m updating my code to use !is_array() though