Php array do conjunto de chaves

Encontrei este post que me ajudou:Dividir uma string para formar chaves de matriz multidimensional?

De qualquer forma, isso funciona como um encanto quando se trata de valores de string, mas se as chaves de array contiverem números inteiros, então ele perde isso.

Aqui está a demonstração:

Eu tenho um conjunto de chaves:

Array
(
    [0] => variable_data
    [1] => 0
    [2] => var_type
)

E método para criar um array aninhado

function constructArray( &$array_ptr, $keys, $value )
    {
        // extract the last key
        $last_key = array_pop ( $keys );

        // walk/build the array to the specified key
        while ( $arr_key = strval( array_shift ( $keys ) ) )
        {
            if ( !array_key_exists ( strval($arr_key), $array_ptr ) )
            {
                $array_ptr[ strval($arr_key) ] = array ( );
            }
            $array_ptr = &$array_ptr[ strval($arr_key) ];
        }

        // set the final key
        $array_ptr[ $last_key ] = '$value';
    }

E eu uso assim:

$keys = array(
    'variable_data',
    '0',
    'var_type'
);
    $clean_arr = array();
    constructArray($clean_arr, $keys, 'asd');

mas a saída é assim:

Array
(
    [variable_data] => Array
        (
            [var_desc] => $value
        )

)

Como você vê, o índice variable_data não contém 0 índice. Eu testei quase tudo que eu poderia saber para trabalhar, mas não deu. Alguém que tenha uma pista melhor?

questionAnswers(1)

yourAnswerToTheQuestion