Complete the code to declare a variable with an integer type.
<?php
$number = [1];
?>The variable $number should be assigned an integer value. The option 42 is an integer, while "42" is a string, true is a boolean, and 3.14 is a float.
Complete the code to declare a function that returns a string type.
<?php function greet(): [1] { return "Hello!"; } ?>
The function greet returns a string, so the return type should be string. Other options represent different types.
Fix the error in the code by completing the type declaration for the parameter.
<?php function doubleValue([1] $num): int { return $num * 2; } ?>
string or bool causes type mismatch errors.The function expects an integer parameter to multiply and return an integer. Declaring the parameter as int ensures type safety.
Fill both blanks to create an array with integer keys and string values.
<?php $fruits = array([1] => [2]); ?>
The array key should be an integer 1, and the value should be a string like "apple". Other options are either wrong types or values.
Fill all three blanks to declare a typed class property and assign it a value.
<?php class Person { public [1] $name = [2]; public [3] $age = 30; } ?>
The property $name is a string and should be assigned a string value like "John". The property $age is an integer type.