1

Is it possible to make something like that:

$array = array('id' => '5', 'something_else' => 'hi');

function some_function($id, $something_else)
{
 echo $something_else;
}

some_function(extract($array));

This code is giving me true/false and not $id,$something_else, etc..

It is important for me to do something like that, because I have different list of variables for each function ( I'm working on my ( let's call it ) "framework" and I want to pass list of variables instead of array with variables. This code is actually going in my router so it's not quite that simple, but in the end it comes to that ).

1 Answers1

0

I assume you know how your array is built. So, why do not you just pass an array as a parameter and then use it in your function ?

If you do something like this you can access to your array's values :

echo $array['something_else'];

And build your function like this :

$array = array('id' => '5', 'something_else' => 'hi');

function some_function($an_array)
{
 echo $an_array['something_else']; // value for something_else
}

some_function($array);

Or if you don't want to change function's parameters, call it like this :

some_function($array['id'], $array['something_else']);
David
  • 453
  • 3
  • 14
  • because it's not that fun, that's why :) and not as convenient, as call_user_func_array. – user2768251 Sep 11 '13 at 13:45
  • Yes that's right. But I you want to go futher and optimise your code, take a look at this [post](http://stackoverflow.com/questions/8343399/calling-a-function-with-explicit-parameters-vs-call-user-func-array). Just food for thought :) – David Sep 11 '13 at 13:55