note 107621 modified in function.curl-setopt by danbrown

From: Date: Thu, 10 May 2012 20:28:16 +0000
Subject: note 107621 modified in function.curl-setopt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187810@lists.php.net to get a copy of this message
I noted something when using CURLOPT_POSTFIELDS in combination with arrays from PHP.

You may supply an array, but there may not be any sub-arrays in this array, as this will give Array-to-string-conversion notice.

Example:

<?php
$ch = curl_init();

# this works
$data = array('name' => 'value');

# this gives "Notice: Array to string conversion..."
$data = array('name' => array('subname' => 'subvalue'));

curl_setopt($ch, CURLOPT_URL, 'http://localhost/test.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?> --was-- I noted something when using CURLOPT_POSTFIELDS in combination with arrays from PHP. You may supply an array, but there may not be any sub-arrays in this array, as this will give Array-to-string-conversion notice. Example: $ch = curl_init(); # this works $data = array('name' => 'value'); # this gives "Notice: Array to string conversion..." $data = array('name' => array('subname' => 'subvalue')); curl_setopt($ch, CURLOPT_URL, 'http://localhost/test.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch); http://php.net/manual/en/function.curl-setopt.php

« previous php.notes (#187810) next »