使用POST将数组传递到另一个页面

时间:2011-06-18 12:39:44

标签: php arrays post

如何将数组传递到另一个页面?   我的代码有什么问题?

$r=mysql_query("select * from pay where PayID=1");
$ar=array();
while ($record=mysql_fetch_array($r))
{
array_push($ar,$record['Reserveid']);
}
var_dump($ar);
$url = 'http://--/a.php';
$client = curl_init($url);
curl_setopt($client, CURLOPT_POST,1);
$data = array(
    'r' =>$ar
);
curl_setopt($client, CURLOPT_POSTFIELDS,$data);
curl_setopt ($client, CURLOPT_RETURNTRANSFER,1);
curl_setopt($client, CURLOPT_FOLLOWLOCATION, 1);
$response = curl_exec($client);
echo $response;

a.php只会

$r=$_POST['r'];
var_dump($r);

输出

array(3) { ...... } 
-------------------------------
string(5) "Array"

1 个答案:

答案 0 :(得分:1)

$data应该是:

$data = http_build_query(array(
    'r' => $ar
));