0

Lets say I have this code:

<?php 
function sayHello($forename = 'John', $lastname = 'doe') {
    return 'Hello '.$forename . ' ' . $lastname;
}
?>

if I call this function like:

sayHello();

it returns

Hello John doe

but what if my first name is correct and I want to change only my lastname?

I can't do this:

sayHello(,,'lastname')

is there a way to leave the firstname alone and only change the lastname?

Ralph Schipper
  • 701
  • 2
  • 12
  • 24
  • You can't, unfortunately. – John Dvorak Jun 14 '14 at 14:36
  • 1
    See also: http://stackoverflow.com/questions/1620737/using-default-value-when-calling-a-function, http://stackoverflow.com/questions/10597114/php-default-function-parameter-values-how-to-pass-default-value-for-not-last, http://stackoverflow.com/questions/5968965/php-default-arguments, http://stackoverflow.com/questions/3978929/php-function-with-optional-parameters, https://www.google.com/search?q=php%20default%20function%20arguments+site:stackoverflow.com – Wesley Murch Jun 14 '14 at 14:38

0 Answers0