tags:

views:

31

answers:

2

Is there a way I can check if a function is true inside another function?

For example.

function Name() {
    //check database
}

function Send() {
    if(Name() == TRUE){
        //do something
    }
}
+2  A: 

Sure: just make sure the function returns TRUE:

function Name() {
  echo 'Some Name';

  return TRUE;
}

function Send() {
  if (Name() == TRUE) {
    // Do something
  }
}
Mark Trapp
Sneaky! 20 seconds ahead.
Michael
do I add return TRUE; at the end of the function
jsnag
You return TRUE when you want to leave the function and return the value TRUE: in this case, it's at the end, but in other cases it might be somewhere else or not at all (for example, if you start adding logic to your function).
Mark Trapp
the Return will exit and return the value out of the function, so you return true at the point which the function has been proven true, or false for that matter
Craig
A: 

*Edit: What Mark Trapp said. ;)

That should work. You would just need to return true; or return false; in the Name() function and you should be set.

Michael
If you're removing your answer by editing, then you might as well delete the answer.
Gert G