0
0

More than 1 year has passed since last update.

関数外の変数の初期値をコール

Posted at

関数外の変数

qiita.php
$number = 1 

をstatic(静的)変数を使用する

qiita.php
function test(){
    static $number;
    $number++;
}

とすると最初にコールされたときのみ初期値を代入

別の処理で$numberが変わっても関数外で宣言した初期値が参照される

参考

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0