How can I convert a PHP function's parameter list to an associative array?

The you can do this using compact: function myFunc($a, $b, $c) { $params = compact('a', 'b', 'c'); // ... } Or, get_defined_vars() will give you an associative array of all the variables defined in that scope, which would work, but I think this might also include $_POST, $_GET, etc... Otherwise, you can use func_get_args to get a list of all the arguments passed to the function. This is not associative though, since it is only data which is passed (that is, there's no variable names). This also lets you have any number of arguments in your function.

Or, just specify one argument, which is an array: function myFunc($params) { } compact() seems to be closest to what you're after though.

The reason I don't like this is the variable names have to be repeated. – Fragsworth Sep 14 '09 at 2:53 look at get_defined_vars then. – nickf Sep 14 '09 at 2:58.

Get_defined_vars() is what you need if no other vars are defined before its called inside the function (you can ensure this by making it the first thing you do inside the function). Function my_function($a, $b, $c) { $params = get_defined_vars().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions