第6章 ユーザー定義関数 / 第4回 模擬試験

次のコードの実行結果として正しいものはどれか。 ```php function counter() { static $count = 0; $count++; return $count; } print counter() . counter() . counter(); ```

123 正解
111
000
333
解説
`static`変数は呼び出し間で値が保持されるため、1回目は1、2回目は2、3回目は3が返され、結合すると`123`になります。(参照: 独習PHP 第4版 第6章 ユーザー定義関数 6.2.3節 静的変数 p.276〜277)