0
0
PHPprogramming~10 mins

$_GET for URL parameters in PHP - Interactive Code Practice

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

Complete the code to get the value of the URL parameter named 'name'.

PHP
<?php
$name = $_GET[[1]];
echo "Hello, $name!";
?>
Drag options to blanks, or click blank then click option'
A"name"
B"value"
Cname
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the parameter name.
Using a variable instead of a string key.
2fill in blank
medium

Complete the code to check if the URL parameter 'age' is set.

PHP
<?php
if (isset($_GET[[1]])) {
    echo "Age is set.";
} else {
    echo "Age is not set.";
}
?>
Drag options to blanks, or click blank then click option'
Aage
B"age"
CAGE
D"AGE"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted parameter names in isset().
Using uppercase letters instead of lowercase.
3fill in blank
hard

Fix the error in the code to safely get the 'city' parameter or use 'Unknown' if not set.

PHP
<?php
$city = $_GET[[1]] ?? 'Unknown';
echo "City: $city";
?>
Drag options to blanks, or click blank then click option'
A"City"
Bcity
CCity
D"city"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys causing undefined index errors.
Using wrong case for parameter names.
4fill in blank
hard

Fill both blanks to create an associative array with key as parameter name and value from $_GET for 'user'.

PHP
<?php
$data = [[1] => $_GET[[2]]];
print_r($data);
?>
Drag options to blanks, or click blank then click option'
A"user"
B"email"
Cuser
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys causing errors.
Mixing parameter names between key and value.
5fill in blank
hard

Fill all three blanks to loop through $_GET and print each parameter and its value.

PHP
<?php
foreach ($_GET as [1] => [2]) {
    echo [3] . ': ' . [2] . "<br>";
}
?>
Drag options to blanks, or click blank then click option'
A$key
B$value
C$param
D$item
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable for key and value.
Using undefined variables in echo.