User defined variables in PHP

A user may define a new variable in a PHP script. What is the scope of that variable?

If a variable was defined in the scope of main code, than this variable has global scope by default.

Variables that had been defined within a function, have local scope. Meaning access to them is available within this function only.

To overcome this, a variable can be declared with global keyword in front of it.

YouTube video

Comments

Popular posts from this blog

Absolute and relative path in HTML pages

Errors

goto PHP operator