Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to cast the variable $value to an integer.
PHP
$intValue = [1]$value; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using (string) instead of (int) for integer casting.
Forgetting the parentheses around the type.
✗ Incorrect
In PHP, to cast a variable to an integer, you use (int) before the variable.
2fill in blank
mediumComplete the code to cast the variable $value to a boolean.
PHP
$boolValue = [1]$value; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using (int) or (string) instead of (bool).
Missing parentheses around the type.
✗ Incorrect
Use (bool) to cast a variable to boolean in PHP.
3fill in blank
hardFix the error in the code to cast $value to a float.
PHP
$floatValue = [1]$value; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using (int) instead of (float).
Omitting parentheses.
✗ Incorrect
To cast to float, use (float) before the variable in PHP.
4fill in blank
hardFill both blanks to cast $value to a string and then to an integer.
PHP
$intValue = [1][2]$value;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of casts.
Using incorrect types for casting.
✗ Incorrect
First cast to string with (string), then cast that result to integer with (int).
5fill in blank
hardFill all three blanks to cast $value to boolean, then to float, then to integer.
PHP
$finalValue = [1][2][3]$value;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Incorrect order of casts.
Using (string) instead of one of the required types.
✗ Incorrect
Casting is done from right to left: first to boolean, then float, then integer.