PHPPHP8 min read

Variable Scope in PHP

Understand local, global, and static scope in PHP functions.

Jessica Lee
December 21, 2025
0.0k0

Scope defines where a variable can be used. ## Local scope ```php function test() { $x = 10; echo $x; } ``` ## Global scope ```php $x = 5; function show() { global $x; echo $x; } ``` ## Static variables ```php function counter() { static $count = 0; $count++; echo $count; } counter(); // 1 counter(); // 2 ``` > Next: Superglobals like $_GET and $_POST.

#PHP#Scope#Beginner