You cannot do what you want, only with default options. By default, they apply only to missing arguments, and only the last arguments may be missing.
You can add lines like
$vega = $vega ? $vega : 'carrot';
and call the function like
testParam('apple',false,'something');
or use the more general method of passing parameters in an array with parameter names in the form of keys. Sort of
function testparam($parms=false) { $default_parms = array('fruit'=>'orange', 'vega'=>'peas', 'starch'=>'bread'); $parms = array_merge($default_parms, (array) $parms); echo '<br>fruit = $parms[fruit]'; echo '<br>vega = $parms[vega]'; echo '<br>starch = $parms[starch]'; } testparm('starch'=>'pancakes');
This is a bit more verbose, but it is also more flexible. You can add parameters and default values ββwithout changing existing subscribers.
Lucky source share