0
0
PHPprogramming~10 mins

$_REQUEST behavior 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 access a value from the $_REQUEST superglobal.

PHP
<?php
$value = $_REQUEST[[1]];
echo $value;
?>
Drag options to blanks, or click blank then click option'
A"email"
B"username"
C"password"
D"age"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the key name.
Using $_REQUEST without a key.
2fill in blank
medium

Complete the code to check if a key exists in $_REQUEST.

PHP
<?php
if (isset($_REQUEST[[1]])) {
    echo "Key exists.";
} else {
    echo "Key does not exist.";
}
?>
Drag options to blanks, or click blank then click option'
Auser_name
B"user_name"
C"user"
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable without quotes as the key.
Using empty quotes or wrong key name.
3fill in blank
hard

Fix the error in the code to correctly retrieve a POST value using $_REQUEST.

PHP
<?php
// Assume form method is POST
$name = $_REQUEST[1]"name"];
echo $name;
?>
Drag options to blanks, or click blank then click option'
A("
B->
C"
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using object operator -> on an array.
4fill in blank
hard

Fill both blanks to create a filtered array from $_REQUEST with keys longer than 4 characters.

PHP
<?php
$filtered = array_filter($_REQUEST, function($key) {
    return strlen($key) [1] 4;
}, [2]);
print_r($filtered);
?>
Drag options to blanks, or click blank then click option'
A>
B==
CARRAY_FILTER_USE_KEY
DARRAY_FILTER_USE_BOTH
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Not specifying the flag to filter by keys.
5fill in blank
hard

Fill all three blanks to create a new array with uppercase keys and values from $_REQUEST where values are not empty.

PHP
<?php
$result = array_combine(
    array_map([1], array_keys($_REQUEST)),
    array_filter($_REQUEST, function($value) {
        return $value [2] '';
    })
);
print_r($result);
?>
Drag options to blanks, or click blank then click option'
Astrtoupper
B!=
C!==
Dempty
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty() inside array_filter callback incorrectly.
Using wrong comparison operators.