ㄧ计把计

硄筁把计睲虫肚患癟ㄧ计硆腹だ筳砞﹚笷Α睲虫

PHP や穿肚患把计箇砞硄筁まノ肚患の箇砞把计跑把计睲虫度 PHP 4 ㎝尿セいや穿癟叫把酚跑把计睲虫㎝疉の闽羛ㄧ计 func_num_args()func_get_arg() の func_get_args()PHP 3 い硄筁肚患皚把计笷摸狦

ㄒ 17-5. ㄧ计肚患皚

<?php
function takes_array($input)
{
    echo 
"$input[0] + $input[1] = "$input[0]+$input[1];
}
?>

硄筁まノ肚患把计

箇砞薄猵ㄧ计把计硄筁肚患τㄏㄧ计ず﹚э跑把计ウぃ穦э跑ㄧ计场璝狦辨甧砛ㄧ计эウ把计ゲ斗硄筁まノ肚患把计

璝狦稱璶ㄧ计把计羆琌硄筁まノ肚患ㄧ计﹚竡い赣把计玡箇才腹 &

ㄒ 17-6. ノまノ肚患ㄧ计把计

<?php
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.'
?>

箇砞把计

ㄧ计﹚竡 C++ 夹秖把计箇砞

ㄒ 17-7. ㄧ计い箇砞把计ノ硚

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

絏琿块琌

Making a cup of cappuccino.
Making a cup of espresso.

PHP 临甧砛ㄏノ皚㎝疭摸 NULL 箇砞把计ㄒ

ㄒ 17-8. ㄏノ獶夹秖摸箇砞把计

<?php
function makecoffee($types = array("cappuccino"), $coffeeMaker NULL)
{
    
$device is_null($coffeeMaker) ? "hands" $coffeeMaker;
    return 
"Making a cup of ".join(", "$types)." with $device.\n";
}
echo 
makecoffee();
echo 
makecoffee(array("cappuccino""lavazza"), "teapot");
?>

箇砞ゲ斗琌盽秖笷Αぃ琌ㄒ跑秖摸Θ┪琌ㄧ计㊣

叫猔種讽ㄏノ箇砞把计ヴ箇砞把计ゲ斗ヴ獶箇砞把计凹玥ㄧ计盢ぃ穦酚箇戳薄猵σ納絏耞

ㄒ 17-9. ㄧ计箇砞把计ぃタ絋ノ猭

<?php
function makeyogurt($type "acidophilus"$flavour)
{
    return 
"Making a bowl of $type $flavour.\n";
}

echo 
makeyogurt("raspberry");   // won't work as expected
?>

瓃ㄒ块琌

Warning: Missing argument 2 in call to makeyogurt() in
/usr/local/etc/httpd/htdocs/php3test/functest.html on line 41
Making a bowl of raspberry .

瞷ゑ耕ㄒ㎝硂ㄒ

ㄒ 17-10. ㄧ计箇砞把计タ絋ノ猭

<?php
function makeyogurt($flavour$type "acidophilus")
{
    return 
"Making a bowl of $type $flavour.\n";
}

echo 
makeyogurt("raspberry");   // works as expected
?>

硂ㄒ块琌

Making a bowl of acidophilus raspberry.

猔:  PHP 5 癬箇砞硄筁まノ肚患

跑把计睲虫

PHP 4 の蔼セ竒穦璹ㄧ计いや穿跑把计睲虫硂痷虏虫ノ func_num_args()func_get_arg()㎝ func_get_args() ㄧ计

礚惠疭粂猭把计睲虫ご礛镑砆絋礚粇肚患倒ㄧ计夹非笲锣