I am interested to know if there is a way to call a function using an associative array to declare parameters.
For example, if I have this function:
function test($hello, $world) {
echo $hello . $world;
}
Is there any way to call it something like this?
call('test', array('hello' => 'First value', 'world' => 'Second value'));
I am familiar with using call_user_funcand call_user_func_array, but I am looking for something more general that I can use to call various methods when I do not know what parameters they are looking ahead of time.
Edit: The reason for this is to create a single interface for the API. I accept JSON and convert it to an array. Thus, I would like various methods to be called and pass values ββfrom JSON input to methods. Since I want to be able to call a set of different methods from this interface, I want to pass parameters to functions without knowing in what order they should be. I think using reflections will give me results, m looking for.
source
share