彻 17. ㄧ计

穦璹ㄧ计

ㄧ计パ粂猭ㄓ﹚竡

ㄒ 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 ($makefoofoo();

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);
    }
}
?>