You can set the default value when declaring the function:
function MyFunction($conditionArg, $arg1=false, $arg2=false, $arg3=false, $arg4=false) {
if($conditionArg == "something") {
// use arguments 1 and 2
}
elseif($conditionArg == "something else") {
// use arguments 3 and 4
}
}
In the above example only the $conditionArg is now required, all else would default to false in the function's scope.
It can be defaulted to anything, string int, null etc.
In an example like this, Another option is to mimic a pythonic kwargs array and pass one argument as an array only including the required arguments as array elements...
MyFunction($args = array())
{
if(isset($args['condition']))
{
if($args['condition'] === "something")
{
//make hay
}
elseif($args['condition'] === "derp")
{
//make a different kind of hay
}
}
}
to take the second example one step further, if the first item is always required, then pass that first separately and pass the argument array second:
MyFunction($conditionArg, $args = array())
{
if($condition === "something")
{
//use $args['one'], $args['two']
}
elseif($condition === "derp")
{
//use $args['three'], $args['four']
}
}