Bird
0
0

Which of the following is the correct syntax to get the type of a variable $var using gettype() in PHP?

easy📝 Syntax Q12 of 15
PHP - Type Handling
Which of the following is the correct syntax to get the type of a variable $var using gettype() in PHP?
Agettype $var;
Btypeof $var;
Ctypeof($var);
Dgettype($var);
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct function syntax in PHP

    PHP functions require parentheses around arguments, so gettype($var); is correct syntax.
  2. Step 2: Check other options for syntax errors

    Syntax using typeof is invalid because it is not a PHP function. gettype $var; misses parentheses, which is invalid syntax.
  3. Final Answer:

    gettype($var); -> Option D
  4. Quick Check:

    Function call syntax = gettype($var) [OK]
Quick Trick: Use parentheses with function calls in PHP [OK]
Common Mistakes:
  • Using typeof instead of gettype()
  • Omitting parentheses in function calls
  • Confusing PHP syntax with JavaScript

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes