Search code examples
phpfunctionparametersargumentscall

Call PHP function


I have php function by multi parameter. I want to call this function with setting only last argument. Simple way is setting other argument empty. But it isn't good.

Is any way to call this function with setting last argument and without setting other argument?

See this example:

function MyFunction($A, $B, $C, $D, $E, $F)
{
    //// Do something
}

//// Simple way
MyFunction("", "", "", "", "", "Value");

//// My example
MyFunction(argument6: "Value")

Solution

  • My suggestion is use array instead of using number of argument, For example your function call should be like this.

    $params[6] = 'value';
    MyFunction($params);
    

    For identify that sixth parameter has set

    function MyFunction($params){
     If ( isset($params[6]) ) // parameter six has value
    
     }
    

    I hope that it will be a alternate way