Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Created April 23, 2013 09:29
Show Gist options
  • Save simonewebdesign/5442146 to your computer and use it in GitHub Desktop.
Save simonewebdesign/5442146 to your computer and use it in GitHub Desktop.
Optional parameters in PHP
<?php
function foo() {
$numargs = func_num_args();
echo "Number of arguments: $numargs<br />\n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br />\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment