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? 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. 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. 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 {} 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"; 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 Link to comment https://forums.phpfreaks.com/topic/185619-elseif-problems/#findComment-980081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.