stdClass 对象 - 拆分为 table

stdClass Object - split into table

我正在使用 GoCardless API 创建订阅。我已经创建了它,现在试图在 table 中显示付款。

API returns 一个 stdClass 对象,数组中包含即将到来的付款。我怎样才能在 table 中显示这些内容?

 $SUBS=$client->subscriptions()->get("$SUB");


 Subscription Class
stdClass Object
(
    [id] => SB00024BNFEEHX
    [created_at] => 2020-03-07T20:20:05.025Z
    [amount] => 5998
    [currency] => GBP
    [status] => active
    [name] => 
    [start_date] => 2020-03-12
    [end_date] => 
    [interval] => 1
    [interval_unit] => monthly
    [day_of_month] => 
    [month] => 
    [count] => 
    [metadata] => stdClass Object
        (
            [subscription_number] => 
        )

    [payment_reference] => 
    [upcoming_payments] => Array
        (
            [0] => stdClass Object
                (
                    [charge_date] => 2020-03-12
                    [amount] => 5998
                )

            [1] => stdClass Object
                (
                    [charge_date] => 2020-04-14
                    [amount] => 5998
                )

            [2] => stdClass Object
                (
                    [charge_date] => 2020-05-12
                    [amount] => 5998
                )

            [3] => stdClass Object
                (
                    [charge_date] => 2020-06-12
                    [amount] => 5998
                )

来自我试过的其他问题

$array = json_decode(json_encode($SUBS),true);
echo"$array";

然而这只是displays/printsArray

您想将其转换为 objectarray,这样简单的类型转换就可以了

$SUBS=$client->subscriptions()->get("$SUB");
$SUBS = (array) $SUBS->upcoming_payments;

//for table
print '<table>';
foreach($SUBS as $SUB) {
   print '<tr><td>'.$SUB['charge_date'].'</td><td>'.$SUB['amount'].'</td></tr>';
}
print '<table>';