Start PHP Code RESULT
number 1: 49
number 2: 60
number 3: 44
number 4: 22
number 5: 55
result: 230
End PHP Code RESULT
The PHP Code START
function addNums() {
    $args = func_get_args();
    $ret = "<table border=\"1\">";
    foreach ($args as $key =>  $val) {
        $result += $val;
        $ret .= "<tr><td>number ".($key+1).": </td><td align='right'>$val</td></tr>";
    }
    $ret .= "<tr><td align='right'>result: </td><td>$result</td></tr>";
    $ret .= "</table>";
    return $ret;
}
print addNums(49,60,44,22,55);
The PHP Code END

 

The way that arguments to a function are indexed makes them somewhat array-like. func_get_args() returns an array containing all the arguments passed to the function. That array can be run through a foreach loop.

We simply decant all the arguments into an array variable named $args. Then it is simply a matter of looping through the array.