<<< Previous question <<< Question ID#0385.md >>> Next question >>>
Consider the following PHP script, used to apply a callback function to every element of an array.
function square($val) {
return pow($val, 2);
}
$arr = [1, 2, 3, 4];
/** line **/
$i = 0;
foreach ($squares as $value) {
if ($i++ > 0) {
echo ".";
}
echo $value;
}
What line of code should be substituted with /** line **/ to achieve an output of 1.4.9.16?
- A)
$squares = array_map('square', $arr);
- B)
$squares = array_walk($arr, 'square');
- C)
$squares = call_user_func_array($arr, 'square');
- D)
$squares = call_user_func_array('square', $arr);
Answer
Answer: A