Recall & Review
beginner
What does the
gettype() function do in PHP?The
gettype() function returns the type of a variable as a string, like 'integer', 'string', or 'array'.Click to reveal answer
beginner
Is there a
typeof operator in PHP like in JavaScript?No, PHP does not have a
typeof operator. Instead, it uses functions like gettype() or is_*() functions to check types.Click to reveal answer
beginner
How can you check if a variable is an integer in PHP?
You can use
is_int($var) which returns true if $var is an integer.Click to reveal answer
beginner
What type string does
gettype() return for a boolean variable?It returns the string 'boolean'.
Click to reveal answer
intermediate
Why might you prefer
is_*() functions over gettype() for type checking?Because
is_*() functions return a boolean (true/false), making it easier to write conditions, while gettype() returns a string that you must compare.Click to reveal answer
What does
gettype(123) return in PHP?✗ Incorrect
gettype() returns 'integer' for whole numbers.Which function checks if a variable is a string in PHP?
✗ Incorrect
is_string() returns true if the variable is a string.Does PHP have a
typeof operator like JavaScript?✗ Incorrect
PHP uses
gettype() and is_*() functions for type checking.What will
is_bool(true) return?✗ Incorrect
is_bool() returns true if the variable is boolean.Which of these is NOT a valid return value of
gettype()?✗ Incorrect
'number' is not a valid return value; PHP uses 'integer' or 'double' instead.
Explain how to check the type of a variable in PHP and the difference between
gettype() and is_*() functions.Think about how PHP tells you what type a variable is and how you can test it in conditions.
You got /4 concepts.
Describe why PHP does not have a
typeof operator and how you can achieve similar functionality.Compare PHP and JavaScript type checking methods.
You got /4 concepts.