logo CodeStepByStep logo

array_mystery1

Language/Type: PHP array mystery arrays

Consider the following function:

function array_mystery1($arr) {
    for ($i = 0; $i < count($arr) - 1; $i++) {
        if ($i % 2 == 0) {
            $arr[$i]++;
        } else {
            $arr[$i]--;
        }
    }
    return $arr;
}

For each array below, indicate what the returned array's contents would be after the function array_mystery1 were called and passed that array as its parameter.

[6, 3]
[2, 4, 6]
[1, 2, 3, 4]
[2, 2, 2, 2, 2]
[7, 3, 2, 0, 5, 1]

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.