Complete the code to create an arrow function that returns the square of a number.
$square = fn($x) => [1]; echo $square(4);
The arrow function returns the square by multiplying the input by itself.
Complete the code to create an arrow function that adds 10 to a number.
$addTen = fn($num) => [1]; echo $addTen(5);
The arrow function adds 10 to the input number.
Fix the error in the arrow function that should return the length of a string.
$length = fn($str) => [1]; echo $length('hello');
The correct PHP function to get string length is strlen().
Fill both blanks to create an arrow function that filters an array to keep only numbers greater than 5.
$filter = fn($arr) => array_filter($arr, fn($n) => $n [1] [2]); print_r($filter([3, 7, 2, 9]));
The arrow function uses > 5 to keep numbers greater than 5.
Fill all three blanks to create an arrow function that maps an array to its elements doubled if they are even.
$doubleEven = fn($arr) => array_map(fn($x) => [1] ? [2] : [3], $arr); print_r($doubleEven([1, 2, 3, 4]));
The arrow function checks if a number is even, doubles it if true, otherwise returns it unchanged.