PHP: Define function with variable parameter count? -
Is there a way to define a function in PHP, so that you can define a variable amount of parameters?
In the language I am more familiar with this:
function my function (... left) {/ * left == Paragraph array / return rest. Long; } Myfunction ("foo", "bar"); // returns2;
Thanks!
Yes to get the argument func_num_args ()
and func_get_arg ()
Use:
& lt; Php function dynamic_args () {echo "Number arguments:". Func_num_args () "& lt; br / & gt;"; ($ I = 0; $ i & lt; func_num_args (); $ i ++) {echo "argument $ i =" Func_get_arg ($ i) "
"; }} Dynamic_arriage ("a", "b", "c", "d", "e"); ? & Gt;
You can now use PHP 5.6+:
"; Forex Currency ($ ARG $ AG) {echo $ arg "
"; }} Dynamic_arriage ("a", "b", "c", "d", "e"); ? & Gt;
Comments
Post a Comment