我想这样做:
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!?");
这样我可以忽略传递前两个参数并简单地传递我想要的那个。
这是python中的example。
答案 0 :(得分:8)
不,但你可以传递数组:
function they_said($persons)
{
foreach ($persons as $person => $text)
{
echo "$person said '$text'";
}
}
they_said( array('charlie' => 'Where are the cookies!?') );