FOR EXAMPLE:
Code: Select all
function do_something($foo, $arg2=true, $arg3=true){
// Does something
}
// First call
do_something(10, false);
// Second call
do_something(10, whatever the default is, false);Moderator: General Moderators
Code: Select all
function do_something($foo, $arg2=true, $arg3=true){
// Does something
}
// First call
do_something(10, false);
// Second call
do_something(10, whatever the default is, false);Code: Select all
function do_something($foo=null, $arg2=null, $arg3=null){
$foo = $foo == null ? 'default for foo' : $foo;
$arg2 = $arg2 == null ? 'default for arg2' : $arg2;
$arg3 = $arg3 == null ? 'default for arg3' : $arg3;
echo"$foo, $arg2, $arg3<br/>";
}
// First call
do_something(10, false);
// Second call
do_something(10, null, false);Code: Select all
// Set the defaults
$some_array["value1"] = "hello world";
$some_array["value2"] = true;
$some_array["value3"] = 10;
//Grab some info
function grab_data($some_array) {
$some_array["value1"] = $data_from_over_there;
$some_array["value3"] = 6;
return $some_array;
}
//Grab some more info
function grab_more_data($some_array) {
$some_array["value1"] = $data_from_a_file;
$some_array["value2"] = false;
return $some_array;
}
function do_something($some_array){
// Does something
return $some_array;
}
// First call
print_r(do_something(grab_data($some_array)));
// Second call
print_r(do_something(grab_more_data($some_array)));