cs.punk Posted August 15, 2009 Share Posted August 15, 2009 Wrote something small just to get my point accross <?php if (isset($sumbited)) {//process form if (isset($error)) {echo "Your username is too long"; // at this point I would like it to go to the 'else' right below. @ Section 751 } } else // THIS IS WHERE I WANT IT TO GO {echo "blah blah"; // form data } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170391-hard-to-describe-i-am-looking-for-something-like-return-but-for-if/ Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 <?php $done = 0; if (isset($sumbited)) {//process form if (isset($error)) {echo "Your username is too long"; } else { $done = 1; } } if ($done == 0) {echo "blah blah"; // form data } ?> edit: changed == 1 to == 0, typed it wrong originally Quote Link to comment https://forums.phpfreaks.com/topic/170391-hard-to-describe-i-am-looking-for-something-like-return-but-for-if/#findComment-898847 Share on other sites More sharing options...
.josh Posted August 15, 2009 Share Posted August 15, 2009 Instead of trying to make it go from that place to that other place, I think you need to rethink your structure. You would normally use something like goto but that is spaghetti code programming and is bad practice. What is your overall goal with this? Quote Link to comment https://forums.phpfreaks.com/topic/170391-hard-to-describe-i-am-looking-for-something-like-return-but-for-if/#findComment-898856 Share on other sites More sharing options...
phorman Posted August 15, 2009 Share Posted August 15, 2009 Goto? Yuck!!! If you must use a goto, set what you want to do in a function, and then call the function.. This helps document your code as you go too, and is one step closer to OOP. function doSomething() { // THIS IS WHERE I WANT IT TO GO echo "Your username is too long"; echo "blah blah"; // form data } /*** MAIN PROGRAM BODY ****/ if ($sumbited) {//process form if ($error) { doSomething(); } } or you could do if ( $submitted && $error ) { doSomething(); } Quote Link to comment https://forums.phpfreaks.com/topic/170391-hard-to-describe-i-am-looking-for-something-like-return-but-for-if/#findComment-899036 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.