luminous Posted May 26, 2010 Share Posted May 26, 2010 I'm using th PHP 'goto' function and I've just read you can't jump in or out of methods or loops which is probably why I'm having trouble with this code... $standard_shipping = array("4","5","6"); $free_shipping = array("1","2","3"); $mail_shipping = array("7","8","9"); goto first; first: foreach($standard_shipping as $standard) { if(array_key_exists($standard, $keys)) { $resultsArray = array_slice($resultsArray, 0,2); break; }else { goto second; } } second: foreach($free_shipping as $free) { if(array_key_exists($free, $keys)) { $resultsArray = array_slice($resultsArray, 6); break; }else { goto third; } } third: foreach($mail_shipping as $mail) { if(array_key_exists($mail, $keys)) { $resultsArray = array_slice($resultsArray, -3); break; } } How can I run through this type of method without using the 'goto' function?? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/202961-php-goto-alternative/ Share on other sites More sharing options...
cags Posted May 26, 2010 Share Posted May 26, 2010 In this case you only appear to be using the goto syntax to break out of a loop, just using break should do the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/202961-php-goto-alternative/#findComment-1063618 Share on other sites More sharing options...
phant0m Posted May 26, 2010 Share Posted May 26, 2010 there's also "continue" Quote Link to comment https://forums.phpfreaks.com/topic/202961-php-goto-alternative/#findComment-1063625 Share on other sites More sharing options...
Alex Posted May 26, 2010 Share Posted May 26, 2010 there's also "continue" continue and break do completely different things. continue will skip the current iteration of the loop and move onto the next while break will break out of the loop entirely. Quote Link to comment https://forums.phpfreaks.com/topic/202961-php-goto-alternative/#findComment-1063626 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.