<?php
function sum(...$nums) {
    $val = 0;
    foreach ($nums as $n) {
        $val += $n;
    }
    return $val;
}

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