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 ).

4

1 回答 1

0

我假设你知道你的数组是如何构建的。那么,为什么不直接将数组作为参数传递,然后在函数中使用它呢?

如果你做这样的事情,你可以访问你的数组的值:

echo $array['something_else'];

并像这样构建您的功能:

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

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

some_function($array);

或者,如果您不想更改函数的参数,请像这样调用它:

some_function($array['id'], $array['something_else']);
于 2013-09-11T13:42:00.767 回答