Bird
0
0

Given this PHP code:

hard📝 Application Q9 of 15
PHP - Type Handling
Given this PHP code:
$values = [123, 3.14, "text", true];
$types = [];
foreach ($values as $v) {
$types[] = gettype($v);
}
print_r($types);

What will be the output?
AArray ( [0] => integer [1] => float [2] => string [3] => true )
BArray ( [0] => integer [1] => double [2] => string [3] => boolean )
CArray ( [0] => number [1] => number [2] => text [3] => bool )
DArray ( [0] => int [1] => float [2] => string [3] => bool )
Step-by-Step Solution
Solution:
  1. Step 1: Understand gettype() output for each value

    123 is "integer", 3.14 is "double", "text" is "string", true is "boolean".
  2. Step 2: Check print_r output format

    print_r outputs array keys and values as shown in Array ( [0] => integer [1] => double [2] => string [3] => boolean ).
  3. Final Answer:

    Array ( [0] => integer [1] => double [2] => string [3] => boolean ) -> Option B
  4. Quick Check:

    gettype() returns PHP type strings exactly [OK]
Quick Trick: gettype() returns "double" for floats, not "float" [OK]
Common Mistakes:
  • Expecting "int" or "float" instead of "integer" and "double"
  • Confusing boolean value with string
  • Misreading print_r output format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes