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
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.