ねえ、私は複数の引数を取り、それらをフォーマットする PHP 関数を使用していました。現在、私は次のようなものに取り組んでいます:
function foo($a1 = null, $a2 = null, $a3 = null, $a4 = null){
if ($a1 !== null) doSomethingWith($a1, 1);
if ($a2 !== null) doSomethingWith($a2, 2);
if ($a3 !== null) doSomethingWith($a3, 3);
if ($a4 !== null) doSomethingWith($a4, 4);
}
しかし、次のようなソリューションを使用できるかどうか疑問に思っていました。
function foo(params $args){
for ($i = 0; $i < count($args); $i++)
doSomethingWith($args[$i], $i + 1);
}
ただし、C# の params キーワードや JavaScript の引数配列と同様に、同じ方法で関数を呼び出します。