php - Optional parameters aren't truly optional -
i have real optional parameters in php. realize can this:
function my_function($req_var, $opt_var1 = 90, $opt_var2 = "lala") { die("weeeeeeee!"); } however, if want specify value of $opt_var2, still must specify value $opt_var1.
here's example.
my_function("lala", 90, "omg"); in other words, have explicitly write 90 $opt_var1 though it's $opt_var2 want change.
is possible this?
my_function("lala", default, "omg"); that helpful.
there way array parameters:
function my_func(array $params = array()){ $arg1 = isset($params['one']) ? $params['one'] : 'default'; $arg2 = isset($params['two']) ? $params['two'] : 'default'; $arg3 = isset($params['three']) ? $params['three'] : 'default'; // ... }
Comments
Post a Comment