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
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *