[Solved] Variable number of parameters in PHP [closed]


PHP 5.6 introduces ability to have this exact construct.
From PHP manual:

Argument lists may include the … token to denote that the function accepts a variable number of arguments. The arguments will be passed into the given variable as an array

<?php
function sum($acc, ...$numbers) {
    foreach ($numbers as $n) {
        $acc += $n;
    }
    return $acc;
}

echo sum(1, 2, 3, 4);
?>

http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list

3

solved Variable number of parameters in PHP [closed]