'CURL post array of values with given key

I need to do a POST request with cURL to send an arbitrary number of strings under a given key ("item[]").

As an example, here is an equivalent POST through an HTTP form. This one works as expected:

<form method="post" action="{url}" enctype="multipart/form-data">
    <input type="text" name="item[]" value="">
    <input type="text" name="item[]" value="">
    <input type="text" name="item[]" value="">
    <input type="text" name="id" value="someid">
</form>

I have tried building the request like this (see below), but to no avail. The receiving server receives value "Array" for "item[]" instead of 3 distinct strings.

$data [
   'item[]' => ['item1', 'item2', 'item3'],
   'id' => 'someid'
];
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source