Skip to content
Justice Tech School

Variable Scope and static

Variables inside functions are local. global imports a global and static keeps a value between calls.

Example
function counter() { static $n = 0; return ++$n; }
counter(); counter();
echo counter();

Result

3

Exercise

Keep between calls.

 $n = 0;

Quiz Test

What does static keep?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.