我定义了一个函数,我想在里面使用类似参数的哈希表。
function Foo($param)
{
// Here, I should get fener as key, and bahce as value.
}
Foo('fener' => 'bahce'); // Is there a way like .net's lambda expression ?
而且我不想使用Foo(array('fener' => 'bahce'))
//我知道有可能..
无论如何,
您必须使用 array()
声明数组:
$args = array('fener' => 'bahce');
Foo($args);
或直接:
Foo(array('fener' => 'bahce'));
编辑
从 PHP 5.4 开始,您还可以(从手册中)执行以下操作:
// as of PHP 5.4
$array = [
"foo" => "bar",
"bar" => "foo",
];
因此,您可能会侥幸逃脱:
Foo(['fener' => 'bahce']);