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 に答える