Php variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Php variable

variable inside a block in PHP , is having global scope?? if(1>0) { $x = 10; }

12th Mar 2018, 2:50 AM
Saurav Kumar
Saurav Kumar - avatar
3 Answers
+ 7
To further clarify Mickel's great answers, I'll say specifically, PHP does not support block level variable scope.
12th Mar 2018, 4:01 AM
David Carroll
David Carroll - avatar
+ 4
"Any variable used inside a function is by default limited to the local function scope". That should solve your doubt. In any case, here you have much more information: http://php.net/manual/en/language.variables.scope.php
12th Mar 2018, 3:40 AM
Mickel
Mickel - avatar
+ 3
In the example you gave yes, the variable has a global scope and can be used outside the if statement
12th Mar 2018, 3:49 AM
Mickel
Mickel - avatar