Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP数组搜索Paypal NVP交易_Php_Arrays_Paypal_Nvp - Fatal编程技术网

使用PHP数组搜索Paypal NVP交易

使用PHP数组搜索Paypal NVP交易,php,arrays,paypal,nvp,Php,Arrays,Paypal,Nvp,您好,我正在使用paypal API执行一个查询,我的问题涉及数组和检索密钥的值(这是动态的)。我知道查询工作正常,凭据良好,因为返回了以下数组: array(2) { ["L_TRANSACTIONID0"]=> string(17) "9FX81733DJ079610B" ["L_TRANSACTIONID1"]=> string(17) "5E083945JC6368706" ["L_TRANSACTIONID2"]=> string(17) "7SP75180Y9281

您好,我正在使用paypal API执行一个查询,我的问题涉及数组和检索密钥的值(这是动态的)。我知道查询工作正常,凭据良好,因为返回了以下数组:

array(2) {
["L_TRANSACTIONID0"]=>
string(17) "9FX81733DJ079610B"
["L_TRANSACTIONID1"]=>
string(17) "5E083945JC6368706"
["L_TRANSACTIONID2"]=>
string(17) "7SP75180Y9281954W"
}
我想在foreach循环中断开每个键,但是每个键都是动态的(注意每个键的计数)。 如何在foreach循环中实现这一点?
谢谢,

前几天我刚刚回答了一个类似的问题,所以可能是重复的。在任何情况下,如果这有助于某人,下面是:

function process_response($str)
{
    $data = array();
    $x = explode("&", $str);

    foreach($x as $val)
    {
        $y = explode("=", $val);

        preg_match_all('/^([^\d]+)(\d+)/', $y[0], $match);

        if (isset($match[1][0]))
        {
            $text = $match[1][0];
            $num = $match[2][0];

            $data[$num][$text] = urldecode($y[1]);
        }
        else
        {
            $text = $y[0];
//          $data[$text] = urldecode($y[1]);
        }
    }

    return $data;
}
只需将curl调用的结果馈送到此中,并将结果作为格式化数组

请注意注释掉的行,有一些字段是全局的,例如version,如果您需要这些字段,请取消注释,但是您可能需要在下游调整一些格式代码

作为如何使用的示例,假设您希望将其馈送到PHPExcel对象,您可以这样做:

    $response = your_curl_call($request);
    $data = process_response($response);

    $index = 1;
    foreach($data as $row)
    {
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$index, $row['L_TIMESTAMP'])
            ->setCellValue('B'.$index, $row['L_TIMEZONE'])
            ->setCellValue('C'.$index, $row['L_TYPE'])
            ->setCellValue('D'.$index, $row['L_EMAIL'])
            ->setCellValue('E'.$index, $row['L_NAME'])
            ->setCellValue('F'.$index, $row['L_TRANSACTIONID'])
            ->setCellValue('G'.$index, $row['L_STATUS'])
            ->setCellValue('H'.$index, $row['L_AMT'])
            ->setCellValue('I'.$index, $row['L_CURRENCYCODE'])
            ->setCellValue('J'.$index, $row['L_FEEAMT'])
            ->setCellValue('K'.$index, $row['L_NETAMT']);
        $index++;
    }
foreach($key=>$value形式的数组)