分配给新变量后多维数组中的附加维度

I have a function that returns a 2 dimensional array ($user $door $ result are arrays too):

function test() {
    $erg = array ($user, $door, $result);       
    return($erg);
}

Now in the script I call the function and try to assign it to a new variable:

        $myarray test();
        echo $myarray[0]['id'];

This throws an exception: Index not defined: 'id'. When I add a dimension it works:

        echo $myarray[0][0]['id'];

I dont know where this 2nd dimenstion comes from :-(

The following line:

$erg = array ($user, $door, $result);

indexes your arrays given by the order provided.

So this actually becomes:

$erg = array ("0"=>$user, "1"=>$door, "2"=>$result);

So either your $user array is similar to:

$user = array("0"=>array("id","userid"));

or you call this function several times and every time you call that function it adds a new parent index[0] to the provided array.