8

Possible Duplicate:
named PHP optional arguments?

I want to do this:

function they_said($alice = "", $bob = "", $charlie = "") {
    echo "Alice said '$alice'";
    echo "Bob said '$bob'";
    echo "Charlie said '$charlie'";
}

they_said($charlie => "Where are the cookies!?");

That way I can ignore passing the first 2 arguments and simply pass the one I want.

Here's an example in python.

Community
  • 1
  • 1
Alexander Bird
  • 36,154
  • 41
  • 121
  • 156

1 Answers1

10

No, but you can pass an array:

function they_said($persons)
{
  foreach ($persons as $person => $text)
  {
    echo "$person said '$text'";
  }
}
they_said( array('charlie' => 'Where are the cookies!?') );
ComFreek
  • 28,220
  • 17
  • 99
  • 151