In this blog I am going to to how to declare PHP variable output, PHP Variables Scope, PHP Global and Local Scope, PHP Global Keyword variable quotes and more.
Creating (Declaring) PHP Variables-
In PHP, a variable starts $ sign, this is mandatory for output or result
Variable always start with $ sign,
A variable name cannot start with a number.
A variable must start with a letter or underscore.
ex-
<?php | |
$a = 5; | |
$b = 4; | |
echo $a + $b; | |
$example = "In this line $ for Declaring variable"; | |
echo "<br>"; | |
echo $example; | |
?> |

PHP local scope:
Any variable declared inside a function is considered as in local scopte of function scope. It can be accessible only inside that function where it is declared.
<?php | |
function test(){ | |
$x = "This is PHP local" ; | |
$y = " scope example." ; | |
echo $x . $y; | |
} | |
test(); | |
?> |

PHP global Scope
Any variable declared outside a function is considered as in the global scope. It can be accessed anywhere in the script.
<?php | |
$a= 10; | |
echo "a = ", $a, "<br>"; | |
function test(){ | |
global $a; | |
echo "$a = ", $a, "<br>"; | |
} | |
test(); | |
?> |





Iβm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND