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
https://forums.phpfreaks.com/topic/202961-php-goto-alternative/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.