I just had a broad question that wasn't clearly answered online. Does a variable have a scope and if so does it only apply when it is in a function or does it also extend into everything that has brackets?
|
PHP
PHP Scope of Variables |
|
Apr 4, 2019 09:16 PM
(This post was last modified: Apr 4, 2019 09:18 PM by BottomNotch.)
(Apr 4, 2019 04:25 PM)Jack Drake Wrote: I just had a broad question that wasn't clearly answered online. Does a variable have a scope and if so does it only apply when it is in a function or does it also extend into everything that has brackets? clear online answer here. Local variables (local scope) - A local scope is a restricted boundary of a variable within which code block it is declared. Global variables (special global scope) - As its name, the global scope provides widespread access to the variable declared in this scope. Static variables (local scope) - A static variable is a variable with local scope. A static variable does not lose its value when the program execution goes past the scope boundary. But it can be accessed only within that boundary. Function parameters (local scope) - Function parameters (arguments) are local variables defined within the local scope of the function on which it is used as the argument. SO, for your more specific question, if you declare a variable in a function, it's a local variable. It can only be modified/referenced to in that function. If this is ur desire, this is where you start passing in variables to your functions. |
|
|



![[Image: wKo4TU0.gif]](https://i.imgur.com/wKo4TU0.gif)