Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 864 Bytes

0385.md

File metadata and controls

48 lines (39 loc) · 864 Bytes

Consider the following PHP script, used to apply a callback function to every element of an array.

function square($val) {
    return pow($val2);
}
$arr = [1234];
/** 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