I need to generate a JSON in the following format:
{ 'plan_id' => 2, 'customer_id' => 16, 'payment_method_code' => 'credit_card', 'product_items' => [ [ 'product_id' => 3 ] [ 'product_id' => 4 ] ] }
But I can not get my code in PHP:
$dados_assinatura = array( 'plan_id' => $plano, 'customer_id' => $cliente_id, 'payment_method_code' => 'credit_card', 'product_items' => array() ); foreach ($array_opcionais as $produto) { $dados_assinatura['product_items'][][] = array ( 'product_id' => $produto ); }
The generated JSON gets:
{ "plan_id":"60412", "customer_id":6527983, "payment_method_code":"credit_card", "product_items":[ [ { "product_id":"221663" } ], [ { "product_id":"221666" } ], [ { "product_id":"221667" } ], [ { "product_id":"221668" } ] ] }