Which of the following are true about the scope of variables in PHP?
- Variables declared inside a function have a local scope and cannot be accessed outside the function.
- Variables declared outside all functions have a global scope and can be accessed from anywhere in the script.
- Variables declared with the var keyword have a static scope and retain their values across function calls.
- All of the above
All of the given options are true about the scope of variables in PHP. Variables declared inside a function have a local scope, meaning they can only be accessed within that specific function. Variables declared outside all functions have a global scope, which allows them to be accessed from anywhere in the script. Variables declared with the var keyword (in PHP 4 and earlier versions) have a static scope and retain their values across function calls. Learn more: https://www.php.net/manual/en/language.variables.scope.php
Loading...
Related Quiz
- PHP supports two types of numbers: integers and ______.
- The PHP files should be saved with a ______ extension for the server to parse them.
- You want to check which version of PHP you have installed on your server. How would you do this?
- You have a PHP script and you need to access a constant of a class. How would you do this?
- What are the PHP mail functions used for?