Challenge - 5 Problems
PHP Gettype Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of gettype() for a float?
Consider the following PHP code:
What will be printed?
$value = 3.14;
echo gettype($value);
What will be printed?
PHP
$value = 3.14; echo gettype($value);
Attempts:
2 left
💡 Hint
PHP uses a specific string for floating point numbers in gettype().
✗ Incorrect
In PHP 7.2 and later, gettype() returns "float" for floating point numbers, not "double" or other variants.
❓ Predict Output
intermediate2:00remaining
What does gettype() return for a boolean false?
Given this PHP code:
What is the output?
$flag = false;
echo gettype($flag);
What is the output?
PHP
$flag = false; echo gettype($flag);
Attempts:
2 left
💡 Hint
PHP uses a full word for boolean types in gettype().
✗ Incorrect
gettype() returns "boolean" for both true and false values in PHP.
❓ Predict Output
advanced2:00remaining
What is the output of this gettype check in PHP?
Analyze this PHP snippet:
What will be printed?
$var = 42;
if (gettype($var) === 'integer') {
echo 'Integer!';
} else {
echo 'Not integer';
}
What will be printed?
PHP
$var = 42; if (gettype($var) === 'integer') { echo 'Integer!'; } else { echo 'Not integer'; }
Attempts:
2 left
💡 Hint
Check the exact string returned by gettype() for integers.
✗ Incorrect
gettype() returns "integer" for integer values. The strict comparison === 'integer' matches, so 'Integer!' is printed.
❓ Predict Output
advanced2:00remaining
What error does this typeof check cause?
Look at this PHP code:
What happens when this code runs?
$value = 'hello';
if (typeof($value) === 'string') {
echo 'It is a string';
} else {
echo 'Not a string';
}
What happens when this code runs?
PHP
$value = 'hello'; if (typeof($value) === 'string') { echo 'It is a string'; } else { echo 'Not a string'; }
Attempts:
2 left
💡 Hint
Check if typeof() is a valid PHP function.
✗ Incorrect
PHP does not have a typeof() function. Using it causes a fatal error about undefined function.
🧠 Conceptual
expert2:00remaining
Which statement about gettype() in PHP is TRUE?
Select the correct statement about the behavior of gettype() in PHP.
Attempts:
2 left
💡 Hint
Recall the exact strings gettype() returns for different types.
✗ Incorrect
gettype() returns 'boolean' for true and false, 'integer' for integers, 'float' for floats, and 'NULL' for null values.