Complete the code to assign a boolean true value to the variable.
<?php
$flag = [1];
var_dump($flag);The correct boolean value in PHP is true (all lowercase). It represents the boolean true.
Complete the code to check if the variable is boolean using the correct function.
<?php $value = false; if ([1]($value)) { echo "It is boolean."; } else { echo "It is not boolean."; }
is_boolean which does not exist in PHP.boolval which converts to boolean but does not check type.The function is_bool() checks if a variable is of boolean type in PHP.
Fix the error in the code to correctly convert a string to boolean.
<?php $input = "false"; $boolValue = [1]($input); var_dump($boolValue);
bool as a function which causes error.booleanval which does not exist.The function boolval() converts a value to boolean in PHP. Casting with (bool) is also valid but not listed here.
Fill both blanks to create an array with keys as words and values as their boolean check.
<?php $words = ["yes", "no", "true", "false"]; $result = [[1] => [2] for [1] in $words];
is_bool which checks type but does not convert.The key should be the variable $word and the value should be the boolean conversion boolval($word).
Fill all three blanks to create a filtered array with words whose boolean value is true.
<?php $words = ["", "0", "1", "true"]; $filtered = array_filter($words, function($[1]) { return [2]($[3]); });
boolval for conversion.The variable name in the function is $word. The function boolval converts it to boolean for filtering.