函数的实参可以这样定义:让它接受任意数量的实参:
<?php
function actOnItems(...$items) {
// $items is an array containing 0 or more values
// used to call the function.
}
actOnItems(1, 2, 3, 4); // $items => [1, 2, 3, 4]
如果要在其他实参之外再指定一个可变长度实参,它必须是最后一个实参。
<?php
function writeLines($file_handle, ...$lines)
{
put_file_contents($file_handle, implode("\n", $lines));
}
writeLines('file.txt', "a", "b", "c");