开发者

Static Variable doesnt increment in Php

I have one php function on a seperate php file and I am calling this function from another php file by using an jquery ajax call. The php function is just increment its static value by 1 but its not incremented as I see the output. The static variable doesnt behave as I think.

Whats the reason for that ?

开发者_JAVA技巧Thanks in advance,

Simple function:

function IncrementByOne()
{
    static $count = 0;

    $count++;

    echo $count;
}


Static function variables are persistent across function calls of the same request. They don't keep their value across multiple requests.

Actually, that is true of all PHP variables, apart from the magic $_SESSION variable: They are always reset after the current request ends.

If you want a variable to persist between multiple requests, you can put it into:

  • a session
  • a database
  • a flatfile
  • APC
  • memcached
  • ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜