首页 > 解决方案 > 获取数组 PHP 的内部部分

问题描述

如何在 PHP 中获取长数组的内部部分:示例:

print_r($array) 给出:

Razorpay\Api\Collection Object
(
    [attributes:protected] => Array
        (
            [entity] => collection
            [count] => 1
            [items] => Array
                (
                    [0] => Razorpay\Api\Payment Object
                        (
                            [attributes:protected] => Array
                                (
                                    [id] => payid
                                    [entity] => payment
                                    [amount] => 1000
                                    [currency] => INR
                                    [status] => captured
                                    [order_id] => orderid
                                    [invoice_id] => 
                                    [international] => 
                                    [method] => card
                                    [amount_refunded] => 0
                                    [refund_status] => 
                                    [captured] => 1
                                    [description] => D.
                                    [card_id] => id
                                    [bank] => 
                                    [wallet] => 
                                    [vpa] => 
                                    [email] => example@example.com
                                    [contact] => +91
                                    [notes] => Razorpay\Api\Payment Object
                                        (
                                            [attributes:protected] => Array
                                                (
                                                    [address] => add
                                                    [merchant_order_id] => orid
                                                )

                                        )

                                    [fee] => 20
                                    [tax] => 0
                                    [error_code] => 
                                    [error_description] => 
                                    [created_at] => 1580641472
                                )

                        )

                )

        )

)

这是返回的 Razorpay 付款详细信息。如何从这个数组中获取 id 和其他最里面的项目我想获取 id 和 status 并检查状态是否被捕获或未能验证付款,但是,我无论如何都无法得到它。请帮忙

标签: php

解决方案


终于得到:

$payment = $api->order->fetch($_POST["razorpayorderid"])->payments();
$payid = $payment["items"][0]["id"];

推荐阅读