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?
<?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); ?>
Use http_build_query()
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // The values of variables will be shown but since we don't have them this is what we get
You can then access it normally using the $_POST
superglobal
The best way to accomplish what you're after is to use http_build_query()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With