I intend to produce a checker function which is utilized by another functions. The concept was simple: when the the weather is not satisfied, steer clear of the function by coming back it.

This is actually the original code:

function awesome(){ 
    $a = "2";
    if ($a != "1"){return;} 
    echo "awesome"; 
}

It labored. Since the $a was 2, the function is came back and also the word "awesome" isn't made an appearance. However, you will find several functions to check on. To prevent repetition, i managed to get by doing this:

function test($var){
    if ($var != "1"){return;}
}

function awesome(){
    test("2");
    echo "awesome";
}

function awesomeagain(){
    test("3");
    echo "awesome";
}

however the word "awesome"s are made an appearance, and also the both function awesome() and awesomeagain() aren't came back. How you can return individuals two with the addition of test() function?

Thanks. I truly thank you for help.

function test($var) {
    if ($var != "1"){
        return "awesome";
    }
    // do something else when $var is not "1" here.
}
function awesome(){
    echo test("2");
}
function awesomeagain(){
    echo test("3");
}

There you have it! PHP rocks !! :)

function test( $var ) {
    return ( $var == "1" );
}

function awesome() {
    if ( test("2") ) {
        echo "awesome";
    }
}

function awesomeagain(){
    if ( test("3") ) {
        echo "awesome";
    }
}

Fikry, attempt to re-learn the idea of conditional, this is actually the fundamental programming skill. Without them, you'll make many buggy code and processes.

fYou most likely should not depend on another function preventing another function form running. Do this rather

function test($var){
    if ($var != "1"){return false;} return true;
}

function awesome(){
    if(test("2"))
    echo "awesome";
}

function awesomeagain(){
    if(test("3"));
    echo "awesome";
}

Your test function needs to return something, and you've got to check this value in other functions. Something similar to this:

function test($var) {
  if ($var != "1")
    return false;
  else
    return true;
}

so, your code ought to be such as this:

function awesome() {
  if (test("2"))
    echo "awesome";
}

But, if you wish to enthusiastic inspections, you are able to throw the best. This will seem like this:

function test($var) {
  if ($var != "1")
    throw new Exception();
}

as well as in other functions use

function awesome() {
  try {
    test("2");
    echo "yeah";
  } catch ($e) {}      
}

to come back in the function make use of return keyword

function test($var){
    if ($var == "1"){
        return TRUE;
    }
}

function awesome(){
    if (!test("2")){
        return FALSE;
    }
    echo "awesome";
    return TRUE;
}