Select 来自数组的条纹订阅项目 ID
Select Stripe Subscription Item ID from Array
我在访问此 Stripe API 数组的特定部分时遇到一些问题。我仍在学习使用这种模式并且 API 确实会定期更新,但是这个特定的 ID 在数组中,我不知何故无法弄清楚如何访问,这是我目前所拥有的......
$subscriptions = \Stripe\Subscription::all(array('limit'=>100));
foreach($subscriptions->data as $subscription){
$sub_id = $subscription->id;
$sub_name = $subscription->plan->nickname;
$sub_item_id = $subscription->items;
print_r($sub_item_id);
}
此脚本输出:
Stripe\Collection Object ( [object] => list [data] => Array ( [0] => Stripe\SubscriptionItem Object ( [id] => si_DTLvqerPBwHgZ0 [object] => subscription_item [created] => 1535055364 [metadata] => Stripe\StripeObject Object ( ) [plan] => Stripe\Plan Object ( [id] => hithost [object] => plan [active] => 1 [aggregate_usage] => sum [amount] => [billing_scheme] => tiered [created] => 1535054527 [currency] => gbp [interval] => month [interval_count] => 1 [livemode] => 1 [metadata] => Stripe\StripeObject Object ( ) [nickname] => HitHost [product] => prod_DTLdxcoAqBC6HS [tiers] => Array ( [0] => Stripe\StripeObject Object ( [amount] => 300 [up_to] => 1 ) [1] => Stripe\StripeObject Object ( [amount] => 2 [up_to] => ) ) [tiers_mode] => graduated [transform_usage] => [trial_period_days] => [usage_type] => metered ) [subscription] => sub_DTLv0tZNFaQSEf ) ) [has_more] => [total_count] => 1 [url] => /v1/subscription_items?subscription=sub_DTLv0tZNFaQSEf )
我正在尝试访问的是 [id] => si_DTLvqerPBwHgZ0
我已经尝试了以下方法,但要么出现错误,要么出现空白屏幕。
$sub_item_id = $subscription->items->list;
$sub_item_id = $subscription->items->object->list;
$sub_item_id = $subscription->items->object->list[data];
有人能给我指出正确的方向吗?
我想你想要的是
$sub_item_id = $subscription->items->data[0]->id
如果使用 var_export
instead of print_r
, as it creates valid PHP code for the variable which can then be used on sites like phptester.net,调试这些问题会更容易。
我在访问此 Stripe API 数组的特定部分时遇到一些问题。我仍在学习使用这种模式并且 API 确实会定期更新,但是这个特定的 ID 在数组中,我不知何故无法弄清楚如何访问,这是我目前所拥有的......
$subscriptions = \Stripe\Subscription::all(array('limit'=>100));
foreach($subscriptions->data as $subscription){
$sub_id = $subscription->id;
$sub_name = $subscription->plan->nickname;
$sub_item_id = $subscription->items;
print_r($sub_item_id);
}
此脚本输出:
Stripe\Collection Object ( [object] => list [data] => Array ( [0] => Stripe\SubscriptionItem Object ( [id] => si_DTLvqerPBwHgZ0 [object] => subscription_item [created] => 1535055364 [metadata] => Stripe\StripeObject Object ( ) [plan] => Stripe\Plan Object ( [id] => hithost [object] => plan [active] => 1 [aggregate_usage] => sum [amount] => [billing_scheme] => tiered [created] => 1535054527 [currency] => gbp [interval] => month [interval_count] => 1 [livemode] => 1 [metadata] => Stripe\StripeObject Object ( ) [nickname] => HitHost [product] => prod_DTLdxcoAqBC6HS [tiers] => Array ( [0] => Stripe\StripeObject Object ( [amount] => 300 [up_to] => 1 ) [1] => Stripe\StripeObject Object ( [amount] => 2 [up_to] => ) ) [tiers_mode] => graduated [transform_usage] => [trial_period_days] => [usage_type] => metered ) [subscription] => sub_DTLv0tZNFaQSEf ) ) [has_more] => [total_count] => 1 [url] => /v1/subscription_items?subscription=sub_DTLv0tZNFaQSEf )
我正在尝试访问的是 [id] => si_DTLvqerPBwHgZ0
我已经尝试了以下方法,但要么出现错误,要么出现空白屏幕。
$sub_item_id = $subscription->items->list;
$sub_item_id = $subscription->items->object->list;
$sub_item_id = $subscription->items->object->list[data];
有人能给我指出正确的方向吗?
我想你想要的是
$sub_item_id = $subscription->items->data[0]->id
如果使用 var_export
instead of print_r
, as it creates valid PHP code for the variable which can then be used on sites like phptester.net,调试这些问题会更容易。