함수 인자는 개수에 상관없이 얼마든지 받을 수 있도록 지정할 수 있어요:
<?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");