python中的
python中的
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。
最佳答案
不,但是您可以传递一个数组:
function they_said($persons)
{
foreach ($persons as $person => $text)
{
echo "$person said '$text'";
}
}
they_said( array('charlie' => 'Where are the cookies!?') );
关于php - PHP函数可以有关键字参数吗? (如python),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7704339/