duanpao4172 2019-03-29 13:22
浏览 63

从数组中获取一个值(php)[重复]

This question already has an answer here:

When I print print_r($event_json); it gives me the array below. I need to get just one value from it [type] as in [type] => charge.succeeded (see the top of the array). I tried echo $event_json[0]['type']; but I am getting nothing.

stdClass Object
(
[created] => 1326853478
[livemode] => 
[id] => charge.succeeded_00000000000000
[type] => charge.succeeded
[object] => event
[request] => 
[pending_webhooks] => 1
[api_version] => 2018-10-31
[data] => stdClass Object
    (
        [object] => stdClass Object
            (
                [id] => ch_00000000000000
                [object] => charge
                [amount] => 500
                [amount_refunded] => 0
                [application] => 
                [application_fee] => 
                [application_fee_amount] => 
                [balance_transaction] => txn_00000000000000
                [billing_details] => stdClass Object
                    (
                        [address] => stdClass Object
                            (
                                [city] => 
                                [country] => 
                                [line1] => 
                                [line2] => 
                                [postal_code] => 
                                [state] => 
                            )

                        [email] => 
                        [name] => someemail@yahoo.com
                        [phone] => 
                    )

                [captured] => 
                [created] => 1553691107
                [currency] => usd
                [customer] => cus_00000000000000
                [description] => 
                [destination] => 
                [dispute] => 
                [failure_code] => card_declined
                [failure_message] => Your card was declined.
                [fraud_details] => stdClass Object
                    (
                        [stripe_report] => fraudulent
                    )

                [invoice] => 
                [livemode] => 
                [metadata] => stdClass Object
                    (
                    )

                [on_behalf_of] => 
                [order] => 
                [outcome] => stdClass Object
                    (
                        [network_status] => not_sent_to_network
                        [reason] => merchant_blacklist
                        [risk_level] => highest
                        [risk_score] => 98
                        [seller_message] => Stripe blocked this payment.
                        [type] => blocked
                    )

                [paid] => 1
                [payment_intent] => 
                [payment_method_details] => stdClass Object
                    (
                        [card] => stdClass Object
                            (
                                [brand] => visa
                                [checks] => stdClass Object
                                    (
                                        [address_line1_check] => 
                                        [address_postal_code_check] => 
                                        [cvc_check] => unavailable
                                    )

                                [country] => US
                                [exp_month] => 1
                                [exp_year] => 2022
                                [fingerprint] => Gawa768Trrk4fEmb
                                [funding] => credit
                                [last4] => 0019
                                [three_d_secure] => 
                                [wallet] => 
                            )

                        [type] => card
                    )

                [receipt_email] => 
                [receipt_number] => 
                [receipt_url] => https://pay.stripe.com/receipts/acct_1DU4J1IcP22cq9aQ/ch_1EIbENIcP22cq9aQk7r9xN3u/rcpt_Em9Xy3Ambv1b8QZISOsIHdbxCnLdgup
                [refunded] => 
                [refunds] => stdClass Object
                    (
                        [object] => list
                        [data] => Array
                            (
                            )

                        [has_more] => 
                        [total_count] => 0
                        [url] => /v1/charges/ch_1EIbENIcP22cq9aQk7r9xN3u/refunds
                    )

                [review] => 
                [shipping] => 
                [source] => stdClass Object
                    (
                        [id] => card_00000000000000
                        [object] => card
                        [address_city] => 
                        [address_country] => 
                        [address_line1] => 
                        [address_line1_check] => 
                        [address_line2] => 
                        [address_state] => 
                        [address_zip] => 
                        [address_zip_check] => 
                        [brand] => Visa
                        [country] => US
                        [customer] => cus_00000000000000
                        [cvc_check] => unavailable
                        [dynamic_last4] => 
                        [exp_month] => 1
                        [exp_year] => 2022
                        [fingerprint] => Gawa768Trrk4fEmb
                        [funding] => credit
                        [last4] => 0019
                        [metadata] => stdClass Object
                            (
                            )

                        [name] => someemail@yahoo.com
                        [tokenization_method] => 
                    )

                [source_transfer] => 
                [statement_descriptor] => 
                [status] => failed
                [transfer_data] => 
                [transfer_group] => 
            )

    )

)
</div>
  • 写回答

1条回答 默认 最新

  • doumu1951 2019-03-29 13:24
    关注

    What you are seeing is an stdClass Object and not an array. Do like below:

    <?php
    
    echo $event_json->type;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突