PHP函数怪数组返回

I have this function:

function Test ($test)
{
        [...]

        if ( $res->num_rows == 0 )
                return "BAD";

        $magic_array = array();

        while ( $row = $res->fetch_assoc() )
                $magic_array[] = $row["hex_stream"];

        return $magic_array;
}

if I try:

    $result_array = Test($test);

    var_dump($result_array);

It prints:

array(3) {
  [0]=>
  string(8) "FFD8FFE1"
  [1]=>
  string(8) "FFD8FFE0"
  [2]=>
  string(8) "FFD8FFE8"
}
string(3) "BAD"

It seems like Test() is returning $magic_array and "BAD" at the same time.

Why is it happening?

Thank you

your test() is being called twice

1st time you get your results from var_dump

2nd time in you get bad because

if ( $res->num_rows == 0 ) {
    return "BAD";
}

Its good practice to use {} in your if and while statements