0
0
PHPprogramming~10 mins

Script execution and memory reset 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 print the value of the variable.

PHP
<?php
$counter = 5;
echo [1];
?>
Drag options to blanks, or click blank then click option'
Acounter
B$counter
C5
Decho
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ sign before the variable name.
Trying to print the variable name as a string without $.
2fill in blank
medium

Complete the code to reset the variable $count to zero.

PHP
<?php
$count = 10;
$count = [1];
echo $count;
?>
Drag options to blanks, or click blank then click option'
Anull
Bfalse
C0
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning null instead of zero.
Assigning an empty string which is not a number.
3fill in blank
hard

Fix the error in the code to correctly unset the variable $temp.

PHP
<?php
$temp = 100;
[1]($temp);
echo isset($temp) ? 'Exists' : 'Unset';
?>
Drag options to blanks, or click blank then click option'
Aunset
Bdelete
Cremove
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like delete or remove.
Trying to assign null instead of unsetting.
4fill in blank
hard

Fill both blanks to create an array with keys as numbers and values as their squares, but only for numbers greater than 3.

PHP
<?php
$numbers = range(1, 5);
$squares = array_combine(array_filter($numbers, function($n) {
    return $n [2] 3;
}), array_map(function($n) {
    return $n[1]2;
}, array_filter($numbers, function($n) {
    return $n [2] 3;
}));
print_r($squares);
?>
Drag options to blanks, or click blank then click option'
A**
B+
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of power operator.
Using < instead of > in condition.
5fill in blank
hard

Fill all three blanks to create an associative array with uppercase keys and values greater than zero.

PHP
<?php
$data = ['a' => 1, 'b' => -2, 'c' => 3];
$result = array_filter(array_combine(array_map(function($k) {
    return [1];
}, array_keys($data)), [3]), function($v) {
    return $v [2] 0;
});
print_r($result);
?>
Drag options to blanks, or click blank then click option'
Astrtoupper($k)
B>
Carray_values($data)
Darray_keys($data)
Attempts:
3 left
💡 Hint
Common Mistakes
Using array_keys($data) instead of values for filtering.
Using < instead of > in condition.