Bird
0
0

Which of the following is the correct way to use the global keyword inside a function to access a variable $count defined outside?

easy📝 Syntax Q12 of 15
PHP - Functions
Which of the following is the correct way to use the global keyword inside a function to access a variable $count defined outside?
Aglobal $count;
Buse $count;
Cglobal($count);
Dextern $count;
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP syntax for global variables

    In PHP, to access a global variable inside a function, you write global $variableName; without parentheses.
  2. Step 2: Check each option

    global $count; uses correct syntax. use $count; is invalid in PHP. global($count); uses parentheses which is incorrect. extern $count; uses 'extern' which is not a PHP keyword.
  3. Final Answer:

    global $count; -> Option A
  4. Quick Check:

    Correct syntax = global $var; [OK]
Quick Trick: Use 'global $var;' without parentheses inside functions [OK]
Common Mistakes:
  • Adding parentheses after global
  • Using 'use' or 'extern' keywords incorrectly
  • Forgetting the $ sign before variable name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes