我对php很新,我试图在第一个可选参数后设置一个可选参数?
例如,我有以下代码:
function testParam($fruit, $veg='pota',$test='default test'){
echo '
$fruit = '.$fruit;
echo '
$veg = '.$veg;
echo '
Test = '.$test;
}
如果我拨打以下电话:
echo 'with all parama';
testParam('apple','carrot','some string');
//we get:
//with all parama
//$fruit = apple
//$veg = carrot
//Test = some string
echo '
missing veg';
testParam('apple','','something');
//we get:
//missing veg
//$fruit = apple
//$veg =
//Test = something
echo '
This wont work';
testParam('apple',,'i am set');
我想尝试拨打电话,以便在最后一个例子中我将’pota’显示为默认的$veg参数,但是传入$test’我设置’.
我想我可以将0传递给$veg然后在代码中分支,如果$veg = 0然后使用’pota’,但只是想知道是否有其他语法,因为我无法在php.net中找到任何关于它的内容.