logo CodeStepByStep logo

array_mystery4

Language/Type: PHP array mystery arrays

What are the values of the elements in array $a1 after the following code executes? Note that in PHP, a function parameter defined with "&" prepended to it is passed by reference, and will be changed as a result of any modification within the function.

function array_mystery4(&$a1, &$a2) {
    for ($i = 0; $i < count($a1); $i++) {
        $a1[$i] += $a2[count($a2) - $i - 1];
    }
}
$a1 = [1, 3, 5, 7, 9];
$a2 = [1, 4, 9, 16, 25];
array_mystery4($a1, $a2);           
$a1[0]
$a1[1]
$a1[2]
$a1[3]
$a1[4]

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.