<?php

/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 16/7/21
 * Time: 下午3:37
 */
class funargsTest extends PHPUnit_Framework_TestCase
{
    public function testFunargs()
    {
        foo("1",2,3);
        $sum = add(1,3,4);
    }
}


function foo($par)
{
    $numargs = func_num_args();
    echo "Number of arguments: $numargs<br />\n";
    if ($numargs >= 2) {
        echo "Second argument is: " . func_get_arg(1) . "<br />\n";
    }

    $arg_list = func_get_args();
    for ($i = 0; $i < $numargs; $i++) {
        echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
    }
}

function add($par)
{
    $numargs = func_num_args();
    $arg_list = func_get_args();
    $num = 0;
    for ($i = 0; $i < $numargs; $i++)
    {
        $num += $arg_list[$i];
    }
    return $num;
}

function addbynum($a, $b, $c)
{
    return $a + $b + $c;
}