PHP 函数参数

传值

function takes_array($input)
{
    echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}

引用

function add_some_extra(&$string)
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, and something extra.'

默认值

function makecoffee ($type = "cappuccino")
{
    return "Making a cup of $type.\n";
}
echo makecoffee ();
echo makecoffee ("espresso");