jayjaz Posted December 18, 2009 Share Posted December 18, 2009 What specific problem could we encounter with the last few elseif’s if we have a large if/elseif block where a single variable is being checked against multiple different values and what would be a better solution to using the if/elseif block? Quote Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/ Share on other sites More sharing options...
premiso Posted December 18, 2009 Share Posted December 18, 2009 Post the code you are referring to and what the goal of it is. You can look into case / switch statement instead but it all depends on what the code is etc. Without seeing the code we cannot effectively tell you the proper method or show you a better way to do the checks. Quote Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/#findComment-980056 Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 What you might want to do is define an error class, or more simply something such as: function CheckInput() { if(!isset($_GET['id'])){ trigger_error('ID Not set'); } if(strlen($_GET['id']) >= 30) { trigger_error('ID too long'); } //etc.. } CheckInput(); Instead of: if (isset($_GET['id'])) { if(!empty($_GET['id']) { if (strlen($_GET['id']) > 30) { die('ID too long'); } else { $id = $_GET['id']; } else { die('Please set ID'); // } else { //... }.. As you can see, defining checks, or better yet error classes are cleaner and take less processing time. Quote Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/#findComment-980063 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 i ead else if() doesnt need the {} Quote Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/#findComment-980066 Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 i ead else if() doesnt need the {} What does that have to do with anything? Yes you can do.. if ($this == $that) echo $this; echo "Foo"; Quote Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/#findComment-980075 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 one time i did it both ways and it didnt work Quote Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/#findComment-980081 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.