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

1 Answer 1

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']);
Sign up to request clarification or add additional context in comments.

2 Comments

because it's not that fun, that's why :) and not as convenient, as call_user_func_array.
Yes that's right. But I you want to go futher and optimise your code, take a look at this post. Just food for thought :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.