【问题标题】:get the value of object inside the array in php在php中获取数组内对象的值
【发布时间】:2015-07-24 12:20:35
【问题描述】:

我正在尝试从下面给出的数组中获取merchantAccountId 值

Array
(
        [status] => 1
        [result] => __PHP_Incomplete_Class Object
        (
                [__PHP_Incomplete_Class_Name] => Braintree_Result_Successful
                [success] => 1
                [_returnObjectName:Braintree_Result_Successful:private] => transaction
                [transaction] => __PHP_Incomplete_Class Object
                (
                        [__PHP_Incomplete_Class_Name] => Braintree_Transaction
                        [_attributes] => Array
                        (
                                [id] => 6vk28p
                                [status] => submitted_for_settlement
                                [type] => sale
                                [currencyIsoCode] => USD
                                [amount] => 800.00
                                [merchantAccountId] => contentorganisation
                                [orderId] =>
                                [createdAt] => DateTime Object
                                (
                                        [date] => 2015-07-24 11:51:42
                                        [timezone_type] => 3
                                        [timezone] => UTC
                                )

                        )

                )

        )

)

我的代码是 $result['result']['transaction'] 。 当我打印这个我得到这个错误

Fatal error: Cannot use object of type __PHP_Incomplete_Class as array in.

【问题讨论】:

  • $result['result']->transaction
  • 试试这个:$result['result']->transaction->_attributes['merchantAccountId'] 但我认为_attributes 是私有的或受保护的。
  • 您可能应该事先加载您的类,这样您就有了适当的实例而不是__PHP_Incomplete 实例,然后调用该类的适当方法来获得结果。跨度>

标签: php braintree


【解决方案1】:

结果是 OBJECT 而不是数组,所以你必须通过以下方式调用它:

Array['result']->transaction->_attributes['id']

【讨论】:

    【解决方案2】:

    我在布伦特里工作。您应该可以通过调用$result->transaction->merchantAccountId 访问商家帐户ID,(请参阅Braintree docs)。

    【讨论】:

    • 如果有一种方法可以在一种方法中检索所有数据以用于记录目的,那将非常有用。
    猜你喜欢
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 2021-06-02
    • 2019-09-19
    相关资源
    最近更新 更多