Jump to content

PHP 'goto' alternative


luminous

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.