Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign a string to the variable.
PHP
<?php
$var = [1];
echo gettype($var); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a number without quotes expecting it to be a string.
Using single quotes incorrectly.
✗ Incorrect
The variable is assigned a string value, so gettype() returns "string".
2fill in blank
mediumComplete the code to add an integer and a float, showing PHP dynamic typing.
PHP
<?php $result = 5 + [1]; echo gettype($result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a string instead of a number.
Using a boolean value which converts differently.
✗ Incorrect
Adding an integer and a float results in a float type in PHP.
3fill in blank
hardFix the error in the code to correctly concatenate a string and an integer.
PHP
<?php $text = "Age: "; $age = 30; echo $text [1] $age;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus
+ which performs arithmetic addition instead of concatenation.Using comma which is invalid here.
✗ Incorrect
In PHP, the dot operator . is used to concatenate strings.
4fill in blank
hardFill both blanks to create an array with keys as strings and values as integers.
PHP
<?php $data = ["one" => [1], "two" => [2]]; print_r($data);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers making them strings.
Mixing keys and values types incorrectly.
✗ Incorrect
The keys are strings, and the values should be integers without quotes.
5fill in blank
hardFill all three blanks to create a variable, assign a boolean, and print its type.
PHP
<?php $[1] = [2]; echo gettype($[3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in assignment and echo.
Assigning string "true" instead of boolean true.
✗ Incorrect
The variable named flag is assigned the boolean true, and gettype() prints "boolean".