<p>This <a href="http://my.php.net/static" rel="nofollow noreferrer">example</a> is from php.net:</p>

<pre><code>&lt;?php
function Test()
{
    static $a = 0;
    echo $a;
    $a++;
}
?&gt;
</code></pre>

<p>And this is my code:</p>

<pre><code>function getNextQuestionID()
{
    static $idx = 0;
    return $idx++;
}
</code></pre>

<p>And I use it in JavaScript:</p>

<pre><code>'quizID=' + "&lt;?php echo getNextQuestionID(); ?&gt;"
</code></pre>

<p>Returns 0 everytime. Why?</p>

I believe you misunderstand what static vars do. Try this code and you may understand better:
```
```
echo getNextQuestionID() . ", " getNextQuestionID() . ", " getNextQuestionID();
```
```
And you will see what I mean.
The static var only lives as long as the script does.
The reason it is returning 0 on the first run instead of 1 is because you are using the postfix operator $var++ instead of the prefix version - ++$var. The difference is is that the increment only gets applied when using the postfix operator after the function returns - but if you use the prefix operator it is applied before the function returns.