0

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

API 返回一个 stdClass 对象,其中包含数组中即将支付的款项。我怎样才能在表格中显示这些?

 $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";

然而,这只是显示/打印Array

4

1 回答 1

1

您想将其转换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>';
于 2020-03-07T21:05:50.287 回答