如何从对象中读取值

How to read a value from an object

所以我从 print_r

得到了下一个输出
Coinbase\Wallet\Value\Money Object
(
    [amount:Coinbase\Wallet\Value\Money:private] =>  18945.00
    [currency:Coinbase\Wallet\Value\Money:private] =>  USD
)

我正在使用 Coinbase SDK -> link to github

我的问题是我应该如何读取金额值? 我正在使用

生成它
$buyPrice = $client->getSpotPrice('BTC-USD');

getSpotPrice 函数是 ->

 public function getSpotPrice($currency = null, array $params = [])
{
    if (strpos($currency, '-') !== false) {
        $pair = $currency;
    } else if ($currency) {
        $pair = 'BTC-' . $currency;
    } else {
        $pair = 'BTC-USD';
    }

    return $this->getAndMapMoney('/v2/prices/' . $pair . '/spot', $params);
}

在测试集成中看到了类似的东西,但我不知道如何让它工作:

public function testGetSpotPrice1()
{
    $price = $this->client->getSpotPrice();

    $this->assertInstanceOf(Money::class, $price);
}

任何 help/ideas 将不胜感激,谢谢!

通过

获得值后
$buyPrice = $client->getSpotPrice('BTC-USD');

然后您可以使用(来自来源 https://github.com/coinbase/coinbase-php/blob/master/src/Value/Money.php )...

$amount = $buyPrice->getAmount();
$currency = $buyPrice->getCurrency();
$BTCSellPrice = $client->getSpotPrice('BTC-USD');

//this is what you are looking for
$BTCUSD = $BTCSellPrice->getAmount();