Can php functions use keyword arguments? (e.g. python)

Possible duplicate:
with the name 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 two arguments and just pass the one I want.

Here is an example in python.

+5
source share
1 answer

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!?') );
+6
source

All Articles