Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created April 6, 2010 18:02
Show Gist options
  • Save fixlr/357888 to your computer and use it in GitHub Desktop.
Save fixlr/357888 to your computer and use it in GitHub Desktop.
Default values for passing an array in to a PHP function
<?php
function example($params = array()) {
$defaults = array(
"one" => 1,
"two" => 2,
"three" => 3);
$params = array_merge($defaults, $params);
return $params;
}
print_r(example(array("two" => 4)));
/*
OUTPUT:
Array
(
[one] => 1
[two] => 4
[three] => 3
)
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment