Writing PHP functions that has many parameters/modifiers [closed]

Here’s a guess at a post without a real question. Maybe you can work with dynamic checking of arguments:

function GuessWhoByHowManyMaybe () {
    $NumberOfArguments = func_num_args();

    # get each one
    $ArrayOfArguments = func_get_args();
    for ($i = 0; $i < $NumberOfArguments; $i++) {
        echo "Argument " . $i . " is: " . $ArrayOfArguments[$i] . "\n";
    }

    # or grab one, in particular, right away
    if ($NumberOfArguments >= 2) {
        echo "Second argument is: " . func_get_arg(1) . "\n";
    }

    # example explained below this function
    if ($NumberOfArguments == 0) {
        // some useful code for when there are 0 arguments
    } elseif ($NumberOfArguments == 1) {
        // some useful code for when there is 1 argument
    }
}

You can make it act how you want by adding some code to check the number of parameters and then perform an action assuming that when a certain number of arguments are passed, then that means you can do a certain action. Err.. if you get what I mean…

Leave a Comment