0

我定义了一个函数,我想在里面使用像参数这样的哈希表。

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'))//我可能知道..

4

1 回答 1

1

一种或另一种方式,您必须使用以下方式声明您的数组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']);
于 2013-10-02T14:44:48.323 回答