CURL response as Array


CURL response as Array

当CURL响应以如下格式返回时。

Array
(
    [timestamp] => 20150409065254
    [callback_status_code] => 200
    [fingerprint] => 252839e4790446a4bdd3a353aa232281a7a0b464
    [txnid] => 219773
    [merchant] => ABC0001
    [restext] => Approved
    [rescode] => 00
    [expirydate] => 052016
    [settdate] => 20150409
    [refid] => t1
    [pan] => 444433...111
    [summarycode] => 1
    )

是否有任何方法以数组形式访问其数据它只是数组格式而不是数组

我正在使用以下代码。

$options = array(
        CURLOPT_RETURNTRANSFER => true,   // return web page
    );
$param = http_build_query($data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$content  = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
echo $content;

有人帮忙吗???

您可以尝试此处描述的print_r_reverse()函数:http://php.net/manual/en/function.print-r.php#93529

因此,您可以在某个地方定义这个函数,并将代码的最后几行更改如下:

...
$content = curl_exec($ch);
$myArray = print_r_reverse($content);
$status = curl_getinfo($ch);
curl_close($ch);
// Do something with $myArray

希望能有所帮助。