0
0
PHPprogramming~10 mins

Boolean type 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 assign a boolean true value to the variable.

PHP
<?php
$flag = [1];
var_dump($flag);
Drag options to blanks, or click blank then click option'
ATrue
B"true"
Ctrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using "True" with uppercase T which is not recognized as boolean.
Using quotes around true, making it a string instead of boolean.
2fill in blank
medium

Complete the code to check if the variable is boolean using the correct function.

PHP
<?php
$value = false;
if ([1]($value)) {
    echo "It is boolean.";
} else {
    echo "It is not boolean.";
}
Drag options to blanks, or click blank then click option'
Ais_bool
Bis_true
Cboolval
Dis_boolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_boolean which does not exist in PHP.
Using boolval which converts to boolean but does not check type.
3fill in blank
hard

Fix the error in the code to correctly convert a string to boolean.

PHP
<?php
$input = "false";
$boolValue = [1]($input);
var_dump($boolValue);
Drag options to blanks, or click blank then click option'
A(boolval)
Bbool
Cbooleanval
Dboolval
Attempts:
3 left
💡 Hint
Common Mistakes
Using bool as a function which causes error.
Using booleanval which does not exist.
4fill in blank
hard

Fill both blanks to create an array with keys as words and values as their boolean check.

PHP
<?php
$words = ["yes", "no", "true", "false"];
$result = [[1] => [2] for [1] in $words];
Drag options to blanks, or click blank then click option'
A"word"
Bboolval($word)
C$word
Dis_bool($word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the key which makes it a string literal.
Using is_bool which checks type but does not convert.
5fill in blank
hard

Fill all three blanks to create a filtered array with words whose boolean value is true.

PHP
<?php
$words = ["", "0", "1", "true"];
$filtered = array_filter($words, function($[1]) {
    return [2]($[3]);
});
Drag options to blanks, or click blank then click option'
Aitem
Bboolval
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inside and outside the function.
Using a function other than boolval for conversion.