Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Created November 7, 2013 14:49
Show Gist options
  • Select an option

  • Save mikedugan/7355805 to your computer and use it in GitHub Desktop.

Select an option

Save mikedugan/7355805 to your computer and use it in GitHub Desktop.
take arbitrary # of params to function
<?php
// yes, the argument list can be empty
function foo() {
// returns an array of all passed arguments
$args = func_get_args();
foreach ($args as $k => $v) {
echo "arg".($k+1).": $v\n";
}
}
foo();
/* prints nothing */
foo('hello');
/* prints
arg1: hello
*/
foo('hello', 'world', 'again');
/* prints
arg1: hello
arg2: world
arg3: again
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment