0
0
PHPprogramming~20 mins

Gettype and typeof checks in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Gettype Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of gettype() for a float?
Consider the following PHP code:
$value = 3.14;
echo gettype($value);

What will be printed?
PHP
$value = 3.14;
echo gettype($value);
A"double"
B"float"
C"decimal"
D"real"
Attempts:
2 left
💡 Hint
PHP uses a specific string for floating point numbers in gettype().
Predict Output
intermediate
2:00remaining
What does gettype() return for a boolean false?
Given this PHP code:
$flag = false;
echo gettype($flag);

What is the output?
PHP
$flag = false;
echo gettype($flag);
A"bool"
B"false"
C"boolean"
D"bit"
Attempts:
2 left
💡 Hint
PHP uses a full word for boolean types in gettype().
Predict Output
advanced
2:00remaining
What is the output of this gettype check in PHP?
Analyze this PHP snippet:
$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';
}
AInteger!
BSyntax error
CNot integer
DRuntime error
Attempts:
2 left
💡 Hint
Check the exact string returned by gettype() for integers.
Predict Output
advanced
2:00remaining
What error does this typeof check cause?
Look at this PHP code:
$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';
}
AWarning: Invalid argument
BNot a string
CIt is a string
DFatal error: undefined function typeof()
Attempts:
2 left
💡 Hint
Check if typeof() is a valid PHP function.
🧠 Conceptual
expert
2:00remaining
Which statement about gettype() in PHP is TRUE?
Select the correct statement about the behavior of gettype() in PHP.
Agettype() returns 'boolean' for both true and false values.
Bgettype() returns 'string' for null values.
Cgettype() returns 'float' for floating point numbers.
Dgettype() returns 'int' for integer values.
Attempts:
2 left
💡 Hint
Recall the exact strings gettype() returns for different types.