0
0
PHPprogramming~10 mins

PHP dynamic typing behavior - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Atrue
B"Hello"
C123
D3.14
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a number without quotes expecting it to be a string.
Using single quotes incorrectly.
2fill in blank
medium

Complete 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'
A3.5
Btrue
C"4"
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a string instead of a number.
Using a boolean value which converts differently.
3fill in blank
hard

Fix 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'
A&&
B+
C,
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus + which performs arithmetic addition instead of concatenation.
Using comma which is invalid here.
4fill in blank
hard

Fill 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'
A1
B"1"
C2
D"2"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers making them strings.
Mixing keys and values types incorrectly.
5fill in blank
hard

Fill 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'
Aflag
Btrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in assignment and echo.
Assigning string "true" instead of boolean true.