简体   繁体   中英

How to get PHP CURL to format an array of arguments according to PHP's own specification?

PHP requires query keys with multiple values to have [] at the end. For example:

<input name="key[]" />
<input name="key[]" />

The reason this is frustrating is, when I use CURL in PHP, the PHP implementation of CURL won't convert the array back appropriately. Instead, it just passes key=Array .

I don't want to build the query string from scratch, because I might be transferring files at the same time (which requires CURLOPT_POSTFIELDS to be an array)

curl_setopt($CURL, CURLOPT_POSTFIELDS, $arguments);

Any ideas how to get this to work? I want CURL to format the query string the way PHP would expect to see it if there were multiple values for one key.

Try this:

$arguments = array (
  'key[0]' => 'value1',
  'key[1]' => 'value2',
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM