如何将名为_(下划线)的对象访问到变量中

时间:2013-02-28 18:34:44

标签: php

我有以下对象。在这种情况下,如何将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
)

3 个答案:

答案 0 :(得分:2)

你的顶级对象是一个数组,而不是一个对象。因此,您应该使用$object['GrossAmount']->_来访问该字段。

答案 1 :(得分:0)

简单地做

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

答案 2 :(得分:-1)

您可以尝试使用

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