Posting an array with curl_setopt

Hi,

The attached code is returning “Notice: Array to string conversion in…”. Simply my array is being handled to the remote server as a string containing “Array” word. the rest of the variables are fine.

How can I pass my array ($anarray) without this problem?

Thanks.

<?php
    
    $data = array(
        'anarray' => $anarray,
        'var1' => $var1,
        'var2' => $var2
     );
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "MY_URL");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    
    curl_exec($ch);
    
    ?>

Do you control the script receiving this data?

You can serialize the array and unserialize it on the other end, but if it’s not your page you’re posting it to, you probably don’t mean to be sending an array there.

Yes, I do. Your solution worked perfectly. THANK YOU.