How to tell PHP to use the default parameter in a function call?

I have a piece of code that can be said:

function nums($a = 1, $b = 2, $c){
    echo "$a, $b, $c";
}

nums(?, ?, 3);

Can I somehow replace to tell PHP to use the default values ​​for these arguments and pass only the one argument that is required, or is this done only by placing $ c first in the parameter list, and then optional parameters? ?

+4
source share
1 answer

Put the default parameters at the end, then do not fill in the parameter in the function call.

Example:

function nums($c, $a = 1, $b = 2){
    echo "$a, $b, $c";
}

nums(3);

The default parameters can be overridden by adding them to the function call:

function nums($c, $a = 1, $b = 2){
    echo "$a, $b, $c";
}

nums(3, 12, 27);
+6
source

All Articles