Bird
0
0

What does the global keyword do in PHP?

easy📝 Conceptual Q11 of 15
PHP - Functions
What does the global keyword do in PHP?
AIt deletes a variable from the global scope.
BIt creates a new local variable inside the function.
CIt makes a variable constant and unchangeable.
DIt allows a function to access variables defined outside its scope.
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable scopes in PHP

    Variables defined outside functions are in the global scope and not accessible inside functions by default.
  2. Step 2: Role of the global keyword

    The global keyword inside a function tells PHP to use the variable from the global scope instead of creating a new local one.
  3. Final Answer:

    It allows a function to access variables defined outside its scope. -> Option D
  4. Quick Check:

    global keyword = access outside variables [OK]
Quick Trick: Global lets functions use outside variables directly [OK]
Common Mistakes:
  • Thinking global creates a new variable inside the function
  • Assuming global deletes variables
  • Confusing global with constants

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes