AFVA | Mitchell Posted January 21, 2010 Report Share Posted January 21, 2010 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! Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted January 21, 2010 Administrators Report Share Posted January 21, 2010 How about -> <?php if (!$variable) {do something if the array is empty} else {do something if the array has data} ?> Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted January 21, 2010 Administrators Report Share Posted January 21, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.