好的,我完全忘记了如何在PHP中跳过参数.
让我们说:
function getData($name, $limit = '50', $page = '1') {
...
}
Run Code Online (Sandbox Code Playgroud)
我如何调用此函数以使middle参数采用默认值(即'50')?
getData('some name', '', '23');
Run Code Online (Sandbox Code Playgroud)
以上是否正确?我似乎无法让这个工作.
在PHP 4/5中是否可以在调用时指定一个命名的可选参数,跳过你不想指定的参数(比如在python中)?
就像是:
function foo($a,$b='', $c='') {
// whatever
}
foo("hello", $c="bar"); // we want $b as the default, but specify $c
Run Code Online (Sandbox Code Playgroud)
谢谢