本文介绍了php 函数可以有关键字参数吗?(像蟒蛇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
命名的 PHP 可选参数?
我想这样做:
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!?");
这样我就可以忽略传递前 2 个参数而只传递我想要的参数.
That way I can ignore passing the first 2 arguments and simply pass the one I want.
这是一个 示例在python中.
Here's an example in python.
推荐答案
不,但是你可以传递一个数组:
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!?') );
这篇关于php 函数可以有关键字参数吗?(像蟒蛇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!