2013-02-28 60 views
0

我有以下對象。在這種情況下,我怎樣才能得到GrossAmount(1.10)的價值作爲變量?如何將名爲_(下劃線)的對象存入變量

我曾嘗試:

$gross = $object->GrossAmount->_; 

$id = $object->GrossAmount->currencyID;

確實給我的GBP

當前代碼但是這是行不通的。

Array 
(
    [TransactionID] => 9BBXH1113VA716445A 
    [ParentTransactionID] => 
    [ReceiptID] => 
    [TransactionType] => express-checkout 
    [PaymentType] => instant 
    [PaymentDate] => 2013-02-28T18:26:43Z 
    [GrossAmount] => stdClass Object 
     (
      [_] => 1.10 
      [currencyID] => GBP 
     ) 

    [FeeAmount] => stdClass Object 
     (
      [_] => 0.21 
      [currencyID] => GBP 
     ) 

    [TaxAmount] => stdClass Object 
     (
      [_] => 0.00 
      [currencyID] => GBP 
     ) 

    [ExchangeRate] => 
    [PaymentStatus] => Completed 
    [PendingReason] => none 
    [ReasonCode] => none 
) 

回答

2

你的頂級對象是一個數組,而不是一個對象。所以你應該使用$object['GrossAmount']->_來訪問該字段。

+0

大嘗試,謝謝! – Chris 2013-02-28 18:42:11

-1

您可以用

$gross = $object->GrossAmount->{"_"}; 
+0

至少根據對交互式PHP shell的快速​​測試'_'作爲常規屬性正常工作。 – ThiefMaster 2013-02-28 18:42:05

+0

我想我在考慮在變量命名中不允許使用下劃線。 – Repox 2013-02-28 18:44:19

0

根本就

$object->GrossAmount->{'_'}