简体   繁体   English

获取数组 stdClass 对象的值

[英]Get value of array stdClass Object

I am performing an insertion of values ​​using an api.我正在使用 api 执行值的插入。 then, I send the values ​​correctly and get the return on the same page.然后,我正确发送值并在同一页面上获得回报。 Eg:例如:

<?php
...
$return= $set->createCharge([
   'description'    => 'Strings etc...',
   'amount'     => 10.0
)];

print_r($return);

?> ?>

This print_r Result is:这个 print_r 结果是:

stdClass Object
(
[data] => stdClass Object
    (
        [charges] => Array
            (
                [0] => stdClass Object
                    (
                        [code] => 555
                        [reference] => 66
                        [dueDate] => 23/11/2020
                        [checkoutUrl] => https://url/number_return
                        [link] => https://url_return
                        [installmentLink] => https://url
                        [payNumber] => 9999999999
                        [billetDetails] => stdClass Object
                            (
                                [bankAccount] => 888888
                                [ourNumber] => 12121-9
                                [barcodeNumber] => 0541454141411141414141414
                                [portfolio] => 0001
                            )

                    )

            )

    )

[success] => 1

) )

I tried to get the value '[code'] using the following:我尝试使用以下方法获取值 '[code']:

echo $return[0]['code'];//Dont work

echo $return['data']['charges'][0]['code'];//Dont Work

how can I get the value of [code] or another that is in that array?如何获取 [code] 或该数组中的另一个值?

Each element in the "charges" array is an object. “charges”数组中的每个元素都是一个对象。 A different syntax is used to refer to the members of the object:使用不同的语法来引用对象的成员:

//for an array
echo $someArray['someValue'];

//for an object
echo $someObject->someValue;
echo $someObject->getSomeValue()

Therefore, this is the way for you:因此,这是适合您的方式:

echo $return->data->charges[0]->code;

Or, step by step:或者,一步一步:

var_dump($return);
var_dump($return->data);
var_dump($return->data->charges);
var_dump($return->data->charges[0]);
var_dump($return->data->charges[0]->code);
var_dump($return->data->charges[0]->code->billetDetails);
var_dump($return->data->charges[0]->code->billetDetails->bankAccount);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM