ㄧ计パ粂猭ㄓ﹚竡
ㄒ 17-1. 甶ボㄧ计ノ硚鞍絏
<?php function foo($arg_1, $arg_2, ..., $arg_n) { echo "Example function.\n"; return $retval; } ?>
|
|
ヴΤ PHP 絏常Τ瞷ㄧ计ず﹚ずㄤウㄧ计㎝摸﹚竡
PHP 3 いㄧ计ゲ斗砆㊣ぇ玡﹚竡τ PHP 4
玥ぃΤ硂妓兵ン埃獶ㄧ计ㄢ絛ㄒいΤ兵ン﹚竡
璝狦ㄧ计ㄢ絛ㄒ家ΑΤ兵ン﹚竡ㄤ﹚竡ゲ斗㊣ぇ玡ЧΘ
ㄒ 17-2. Τ兵ンㄧ计
<?php
$makefoo = true;
/* We can't call foo() from here since it doesn't exist yet, but we can call bar() */
bar();
if ($makefoo) { function foo() { echo "I don't exist until program execution reaches me.\n"; } }
/* Now we can safely call foo() since $makefoo evaluated to true */
if ($makefoo) foo();
function bar() { echo "I exist immediately upon program start.\n"; }
?>
|
|
ㄒ 17-3. ㄧ计いㄧ计
<?php function foo() { function bar() { echo "I don't exist until foo() is called.\n"; } }
/* We can't call bar() yet since it doesn't exist. */
foo();
/* Now we can call bar(), foo()'s processesing has made it accessable. */
bar();
?>
|
|
PHP い┮Τㄧ计㎝摸常ㄣΤЫ跑计ず﹚﹚竡场㊣はぇョ礛
PHP ぃや穿ㄧ计更ぃ﹚竡┪琌﹚竡羘ㄧ计
猔:
ㄧ计琌獶糶庇稰ぃ筁㊣ㄧ计硄盽ㄏノㄤ﹚竡Α
PHP 3 瘤礛や穿箇砞把计癟叫把酚箇砞把计琌玱ぃや穿跑把计计PHP 4
や穿ǎ跑把计睲虫㎝疉の闽羛ㄧ计
func_num_args()
func_get_arg()の
func_get_args() 眔癟
PHP い㊣患耴ㄧ计琌璶磷患耴ㄧ计〓よ猭㊣禬筁
100-200 糷穦瘆胊帮舼眖τㄏ瞷ノ竲セ沧ゎ
ㄒ 17-4. 患耴ㄧ计
<?php function recursion($a) { if ($a < 20) { echo "$a\n"; recursion($a + 1); } } ?>
|
|