2012-01-04 54 views
1

我有一個數組,看起來像這樣拉值:使用PHP從陣列

Array (
    [TIMESTAMP] => 2012-01-04T21:36:32Z 
    [CORRELATIONID] => 4564e64d7f75f 
    [ACK] => Failure 
    [VERSION] => 51.0 
    [BUILD] => 2278658 
    [L_ERRORCODE0] => 10764 
    [L_SHORTMESSAGE0] => This transaction cannot be processed at this time. Please try again later. 
    [L_LONGMESSAGE0] => This transaction cannot be processed at this time. Please try again later. 
    [L_SEVERITYCODE0] => Error 
    [L_ERRORPARAMID0] => ProcessorResponse 
    [L_ERRORPARAMVALUE0] => PPAV 
    [AMT] => 25.00 
    [CURRENCYCODE] => USD 
    [AVSCODE] => N 
    [CVV2MATCH] => M 
) 

,如果我想回聲出爲[L_LONGMESSAGE0](其值是「這事務不能在被處理這一次,請稍後再試'),我將如何使用php來做到這一點?

爲了更加清楚,我收到來自PayPal這個數組當我使用這個命令: urldecode(的print_r($ httpParsedResponseAr,真))

因此,考慮到該命令產生上面顯示的陣列,我將如何迴應[L_LONGMESSAGE0]?

在此先感謝您的幫助

回答

2

假設:該陣列是$arr變量中。

echo $arr['L_LONGMESSAGE0']; 
+0

+1,因爲單引號的最佳答案。 – Paulpro 2012-01-04 22:05:55

+0

我只是修改了問題,更清晰 - 不幸的是建議的答覆不工作。當我把$ ARR內部數組,我得到「解析錯誤:語法錯誤,意想不到的‘[’,預計‘)’在C:\ XAMPP \ htdocs中\ site.com \ test.html的上線3」 – 2012-01-04 22:11:42

+0

來吧男人,你是不是真的試圖把剛剛發佈的代碼放入一個變量中呢?你發佈的是數組在PHP中可視化表示的方式。這絕不是_actual_ PHP語法。詳細瞭解如何構建的陣列[這裏](http://php.net/manual/en/language.types.array.php),[這裏](http://www.w3schools.com/php/php_arrays.asp )和/或[這裏](http://www.tizag.com/phpT/arrays.php)。這很容易,你應該能夠弄清楚。 – 2012-01-04 22:16:07

1

如果你的數組存儲在變量$迴應,你會做

echo $response["L_LONGMESSAGE0"]; 
0

有點偏離主題,但我希望你不會將這些信息呈現給買家?
API錯誤響應是指由你,商家解釋,以示給買家一個友好的消息。
至少,你可以做一個簡單的開關;

switch ($httpParsedResponseAr['L_ERRORCODE0']) { 
     case "10764": 
      echo "Unable to process your transaction. Please try a different payment method."; 
      break; 
     case "10002": 
      echo "Unexpected error. Please try again in an hour."; 
      // Log error 
      error_log("10002 error in site",1,"[email protected]"); 
      break; 
     case "10001": 
      echo "Unexpected error from PayPal. Our engineers have been notified."; 
      error_log("10001 in site",1,"[email protected]"); 
      break; 
    }