Complete the code to declare a function that accepts an int or a string.
<?php
function printValue([1] $value) {
echo $value;
}
?>The union type int|string allows the function to accept either an integer or a string.
Complete the code to declare a variable that can hold either an array or null.
<?php
/** @var [1] $data */
$data = null;
?>The union type array|null means the variable can be an array or null.
Fix the error in the function parameter type declaration to accept int or float.
<?php function calculateArea([1] $radius) { return pi() * $radius * $radius; } ?>
The union type int|float allows the function to accept either an integer or a float.
Fill both blanks to declare a function that returns int or string and accepts int or string.
<?php function convert([1] $input): [2] { if (is_int($input)) { return (string)$input; } return strlen($input); } ?>
The function accepts int|string and returns int|string as a union type.
Fill all three blanks to create a function that accepts int|string|null and returns string|int|null.
<?php function processValue([1] $value): [2] { if ($value === null) { return null; } if (is_int($value)) { return (string)$value; } return strlen($value); } /** @var [3] $result */ $result = processValue(123); ?>
The function parameter uses int|string|null, the return type is string|int|null, and the variable is declared with int|string|null.