Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6610079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:47:41+00:00 2026-05-25T19:47:41+00:00

I try to send a multi array via cURL but I can’t find a

  • 0

I try to send a multi array via cURL but I can’t find a nice way to do it.

My code example:

$data = array( 'a' => 'testa', 'b' => 'testb', 'c[d]' => 'test1', 'c[e]' => 'test2' );

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

This will work and give the result I want on the curl_init() site:

print_r( $_POST ) :

Array (

    [a] => testa
    [b] => testb
    [c] => Array (

            [d] => test1
            [e] => test2
    )
)

I’d like to add the c array dynamically like:

$c['d'] = 'test1';
$c['e'] = 'test2';

But if I try to add an array with array_push or [] I always get and (string)Array in the Array without data.

Can anyone help me to do it?

The whole code for faster testing:

$url = 'url_to_test.php';
$data = array( 'a' => 'testa', 'b' => 'testb', 'c[d]' => 'test1', 'c[e]' => 'test2' );
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$buffer = curl_exec ($ch);
curl_close ($ch);

echo $buffer;

The test.php

print_r($_POST);

Thanks for any help!

cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:47:42+00:00Added an answer on May 25, 2026 at 7:47 pm

    In

    $data = array( 'a' => 'testa', 'b' => 'testb', 'c[d]' => 'test1', 'c[e]' => 'test2' )
    

    You’ve simply added new string keys “c[d]” and “c[e]”.

    If you want a nested array, use:

    $data = array( 'a' => 'testa', 'b' => 'testb', 'c' => 
        array( 'd' => 'test1', 'e' => 'test2' )
    )
    

    — EDIT —

    You’re trying to set POST data, which is essentially a set of key value pairs. You can’t provide a nested array. You could, however, serialize the nested array and decode it at the other end. Eg:

    $post_data = array('data' => serialize($data));
    

    And at the receiving end:

    $data = unserialize($_POST['data']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to send a request to my server via GET, but qooxdoo sends
I've written this code to try and send a url as a post value
Im getting a connection refused when I try to send some data to my
I had try to implement the send me log feature into my apps but
I am try to send a mail from my php application.Mail send successfully but
I am getting this error when I try to send via the local server
I try to send data form ajax to cakephp cotroller function loadtooltip(obj, $user_id) {
When I try to send Push Notifications I get this error: Connection refused, but
I try to send a string over the network, this is my code: IPEndPoint
I have following code in a python script try: # send the query request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.