What does a public function handle($request, Closure $next, ...$guards) syntax mean? What are three points?

    1 answer 1

    In versions of PHP 5.6 and above, the argument list may contain an ellipsis ... to show that the function takes a variable number of arguments. Arguments in this case will be passed as an array. For example:

     <?php function sum(...$numbers) { $acc = 0; foreach ($numbers as $n) { $acc += $n; } return $acc; } echo sum(1, 2, 3, 4); ?> 

    The result of this example:

     10 

    Ellipsis (...) can be used when calling a function to unpack an array (array) or a Traversable variable into an argument list:

     <?php function add($a, $b) { return $a + $b; } echo add(...[1, 2])."\n"; $a = [1, 2]; echo add(...$a); ?> 

    The result of this example:

     3 3 

    Documentation