硄筁把计睲虫肚患癟ㄧ计硆腹だ筳砞﹚笷Α睲虫
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 癬箇砞硄筁まノ肚患