Jump to content

Recommended Posts

I have a situation where if certain criteria isn't met I need the function to be 'recalled' or otherwise start from the beginning.

 

For example:

 

function beach(){
echo $do_something; 
if ($do_something != $fun) {
echo "HOW DO I stop and START THE FUNCTION AGAIN FROM BEGINNING?"
} else {
	exit;
}

beach();

 

For some reason I think a loop is in order here?

Well, it probably has a more efficient way to do that, but one thing you could do is create a second function that all it does is to call the function beach(). Something like:

function call_beach() {
beach();
}

 

Then, if your criteria isn't met, you can just call the funcion call_beach()

Well, it probably has a more efficient way to do that, but one thing you could do is create a second function that all it does is to call the function beach(). Something like:

function call_beach() {
beach();
}

 

Then, if your criteria isn't met, you can just call the funcion call_beach()

What exactly would the purpose of that be? Calling call_beach() would be exactly the same thing as calling beach().

 

If you need to call the function from inside the function go ahead, what's stopping you? Just make sure you don't create an infinite loop.

Recursion may be the answer, depending on how $do_something is supposed to be set.

 

function beach()
{
   echo $do_something;
   $do_something = $some_other_thing; // <-- this is the key part... $do_something needs to eventually become 'fun', else you'll have an infinite loop

   if ($do_something !== 'fun') { beach(); }
   else { exit; }
}

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.