php函数中的static变量

function test1_static () {
  static $num = 0;
  $num++;
  echo 'test1_static(): ' . $num;
}
function test2 () {
  $num++;
  echo  'test2(): ' . $num;
}
test1_static(); // test1_static(): 1
test1_static(); // test1_static(): 2
test2 (); // test2(): 1
test2 (); // test2(): 1
评论
:broken_heart: :confounded: :flushed: :frowning: :grinning: :heart: :kissing_heart: :mask: :pensive: :rage: :relaxed: :scream: :smile: :smirk: :sob: :stuck_out_tongue_closed_eyes: :stuck_out_tongue_winking_eye: :wink: