//在自定义函数中,前面加一个&符号,是对返回静态变量的引用
function &test(){
    static $a;
    $a += 1;
    echo $a;
    return $a;
}

//看展示
$t = test();    //$t结果为:1
$t = 5;
$t = test();    //$t结果为:2

$t = &test();   //$t结果为:3
$t = 5;
$t = test();    //$t结果为:6

 

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-28
  • 2021-08-06
  • 2022-12-23
  • 2021-12-06
  • 2021-07-25
  • 2022-12-23
  • 2021-08-20
相关资源
相似解决方案