PHPにおいてすべての引数を配列として取得する方法を知りませんか。
現在私は次のような複数の引数を整形するPHPの関数を使っています。
lang
1function foo($a1 = null, $a2 = null, $a3 = null, $a4 = null){ 2 if ($a1 !== null) doSomethingWith($a1, 1); 3 if ($a2 !== null) doSomethingWith($a2, 2); 4 if ($a3 !== null) doSomethingWith($a3, 3); 5 if ($a4 !== null) doSomethingWith($a4, 4); 6}
しかしこれを関数の機能を保ったまま以下のようなコードに書き換えたいと思っています。
lang
1function foo(params $args){ 2 for ($i = 0; $i < count($args); $i++) 3 doSomethingWith($args[$i], $i + 1); 4}
C#のparamsキーワードやJavaScriptにおける引数の配列のように機能するものを探しています。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。