phpfunctionscopepredefined-variables

PHP: Declaration of arguments in function parameters


First of all, I can't recall the name of this process, but it looks something like this:

function test($alter = FALSE){
    //do stuff
    return $alter;
}

Making $alter = FALSE right in the function declaration

What is that called? How does this work? What happens in the following circumstances?

$result = test();

$result = test(TRUE);


Solution

  • FALSE is defined as the default value if no other value is passed.

    In the case of you examples the results (in order) would be:

    FALSE
    TRUE