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

Popular posts from this blog

php - multilevel menu with multilevel array -

c# - TypeConverter in propertygrid only converts from string, not to -

jQuery UI: Datepicker month format -