Bird
0
0

In PHP, what is the effect of using the global keyword inside a function on a variable?

easy📝 Conceptual Q1 of 15
PHP - Functions
In PHP, what is the effect of using the global keyword inside a function on a variable?
AIt creates a new local variable with the same name inside the function.
BIt allows the function to access and modify the variable defined in the global scope.
CIt makes the variable read-only inside the function.
DIt deletes the global variable after the function executes.
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable scopes

    Variables declared outside functions are in the global scope.
  2. Step 2: Using global inside a function

    The global keyword links the local variable to the global one, allowing access and modification.
  3. Final Answer:

    It allows the function to access and modify the variable defined in the global scope. -> Option B
  4. Quick Check:

    Global keyword links local to global variable [OK]
Quick Trick: Global links local variable to global scope [OK]
Common Mistakes:
  • Assuming global creates a new local variable
  • Thinking global makes variable read-only
  • Believing global deletes the variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes