How to include array data in CURLOPT_POSTFIELDS? [duplicate] How to include array data in CURLOPT_POSTFIELDS? [duplicate] arrays arrays

How to include array data in CURLOPT_POSTFIELDS? [duplicate]


I just wanted to share an alternative to http_build_query()

You can include array inputs with CURLOPT_POSTFIELDS by supplying each subarray item separately.

Instead of...

$videoLinks = array();$videoLinks[0] = 'video1.wmv';$videoLinks[1] = 'video2.wmv';$params = array(    ...    'videoLinks' => $videoLinks;    ...);

... do this ...

$params = array(    ...    'videoLinks[0]' => 'video1.wmv';    'videoLinks[1]' => 'video2.wmv';    ...);


I'm new to cURL and its PHP version, but as far as I know you can do arrays in your option just fine, just don't forget that if you're sending an array of field=>values then you have to set the Content-Type header to multipart/form-data for proper interpretation. That being said, your array for params is formatted wrong. You have that extra comma after your final array value. That might be what's making it bork.