logo CodeStepByStep logo

array_mystery5

Language/Type: PHP array mystery arrays

Consider the following function:

function array_mystery5($arr) {
    for ($i = 0; $i < count($arr) - 1; $i++) {
        if ($arr[$i] > $arr[$i + 1]) {
            $temp = $arr[$i];
            $arr[$i] = $arr[$i + 1];
            $arr[$i + 1] = $temp;
            $arr[0]++;
        }
    }
    return $arr;
}

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

[5, 2, 5, 2]
[30, 10, 20, 50, 40]
[99, 88, 77, 66, 55, 44]

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.