get_named_param()
get_named_param(Mixed $params, String $name, Mixed $default = null) : Mixed
A helper function to get a named parameter.
Parameters
| Mixed | $params | The array or object with named parameters. |
| String | $name | The name of the parameter to look for. |
| Mixed | $default | The default value if it's not found. |
Returns
Mixed —The parameter value.
A common use for this is if you want to support both positional and named parameters from the same call. This only works if the first parameter is never an array or object.
public function mymethod ($param1, $param2=null, $param3=null) { $param2 = get_named_param($param1, 'param2', $param2); $param3 = get_named_param($param1, 'param3', $param3); $param1 = get_named_param($param1, 'param1', $param1); // the rest of the function here. }