Complete the code to declare a function that accepts an integer or a string.
<?php function example([1] $value) { return $value; } ?>
The union type int|string allows the function to accept either an integer or a string.
Complete the code to declare a property that can hold either a float or null.
<?php class Sample { public [1] $price; } ?>
null for nullable properties.The property type float|null means it can be a float or null.
Fix the error in the function parameter type declaration to accept either an array or a string.
<?php
function process([1] $input) {
// process input
}
?>null when not needed.The correct union type is array|string to accept either type.
Fill both blanks to declare a function that returns either an int or a float and accepts a string or int parameter.
<?php function calculate([1] $value): [2] { // calculation logic } ?>
The parameter type string|int allows either type as input, and the return type int|float allows either type as output.
Fill all three blanks to create a class property with a union type, a constructor parameter with a union type, and a method return type union.
<?php class Data { private [1] $info; public function __construct([2] $info) { $this->info = $info; } public function getInfo(): [3] { return $this->info; } } ?>
null when not needed.All three use the union type string|int to allow flexibility in the property, constructor parameter, and method return type.