Zend
200-710 · Question #34
What is the output of the following code? function z($x) { return function_ ($y) use ($x) { return str_repeat($y, $x); }; } $a = z(2); $b = z(3); echo $a(3) . $b(2);
The correct answer is B. 33222. See the full explanation below for the reasoning.
Closures
Question
What is the output of the following code?
function z($x) {
return function_ ($y) use ($x) {
return str_repeat($y, $x);
};
}
$a = z(2);
$b = z(3);
echo $a(3) . $b(2);
Options
- A22333
- B33222
- C33322
- D222333
How the community answered
(27 responses)- A11% (3)
- B78% (21)
- C4% (1)
- D7% (2)
Topics
#closure use#currying#str_repeat#higher-order functions
Community Discussion
No community discussion yet for this question.