Add items to the array without creating a new level

0

I have the following routine that generates an array for me:

$tipo = "V";

if($tipo == "V"){
    $addonTypeSuccess = ["size" => 10, "option" => 'classic', "type" => "volume"];
}

$arrayAWSAgregado[] = array(
    "product_alias" => 'teste',
    "months" => 1,
    $addonTypeSuccess
);

$arrayAWS[] = array(
    "product_alias" => 'teste',
    "os" => 'linux',
    "months" => 1,
    "addons" => $arrayAWSAgregado
);

$dataAssinatura = array(
    'email' => '[email protected]', 
    'order_id' => 29292, 
    'products' => $arrayAWS
);

This generates the following array:

Array
(
    [email] => [email protected]
    [order_id] => 29292
    [products] => Array
        (
            [0] => Array
                (
                    [product_alias] => teste
                    [os] => linux
                    [months] => 1
                    [addons] => Array
                        (
                            [0] => Array
                                (
                                    [product_alias] => teste
                                    [months] => 1
                                    [0] => Array
                                        (
                                            [size] => 10
                                            [option] => classic
                                            [type] => volume
                                        )

                                )

                        )

                )

        )

)

I would like the array [size], [option], and [type] not to be placed inside an array. How can I do this? I wish they were at the same level as [product_alias] and [months].

    
asked by anonymous 25.01.2018 / 20:54

1 answer

2

Use array_merge to merge two or more arrays .

$arrayAWSAgregado[] = array_merge(array(
    "product_alias" => 'teste',
    "months" => 1
), $addonTypeSuccess);
    
25.01.2018 / 20:59