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