在非常嵌套的数组上回显特定值
Echo a specific value on a very nested array
我有一个生成数组的函数(我没有创建该函数,来自 API)然后将其保存到变量($customerList)。我只需要显示整个嵌套数组的一个值;此数组包含所有此代码(显示为 print_r($customerList);):
Array
(
[0] => Customer Object
(
[status:protected] =>
[creation_date:protected] => 2016-01-14T12:07:07-06:00
[balance:protected] =>
[clabe:protected] => 321654qweasd
[derivedResources:protected] => Array
(
[cards] => 123123123123
//a lot of code
如何使用 echo 仅显示“[cards]”上的值?
我试过了
//the for loop {
echo $customerList['0']['derivedResources:protected']['cards'];
和
//the for loop {
echo $customerList['0']['derivedResources']['cards'];
但它什么也没显示。我还没有见过这样的数组,所以可能只是新手的错误。
我认为 "protected" 事情与此有关;但如果我可以显示它,我可以 read/access 对吧?
如果你们需要整个数组(它很长)我可以把它放在这里。
谢谢。
I haven't seen an array like this
它是一个对象数组。学习一些关于 OOP 的知识。
这应该有效:
echo $customerList[0]->derivedResources['cards'];
基于print_r
:
Array
(
[0] => Customer Object
(
[status:protected] =>
[creation_date:protected] => 2016-01-14T12:07:07-06:00
[balance:protected] =>
[clabe:protected] => 321654qweasd
[derivedResources:protected] => Array
(
[cards] => 123123123123
//a lot of code
我们可以模拟:
<?php
$CustomerObject = new \stdClass;
$derivedResources = new \stdClass();
$CustomerObject->derivedResources = ["cards" => 123123123123];
$customerList = [$CustomerObject];
// print_r($customerList);
echo $customerList[0]->derivedResources['cards'];
其中,取消注释 print_r
结果:
Array
(
[0] => stdClass Object
(
[derivedResources] => Array
(
[cards] => 123123123123
)
)
)
123123123123
我有一个生成数组的函数(我没有创建该函数,来自 API)然后将其保存到变量($customerList)。我只需要显示整个嵌套数组的一个值;此数组包含所有此代码(显示为 print_r($customerList);):
Array
(
[0] => Customer Object
(
[status:protected] =>
[creation_date:protected] => 2016-01-14T12:07:07-06:00
[balance:protected] =>
[clabe:protected] => 321654qweasd
[derivedResources:protected] => Array
(
[cards] => 123123123123
//a lot of code
如何使用 echo 仅显示“[cards]”上的值?
我试过了
//the for loop {
echo $customerList['0']['derivedResources:protected']['cards'];
和
//the for loop {
echo $customerList['0']['derivedResources']['cards'];
但它什么也没显示。我还没有见过这样的数组,所以可能只是新手的错误。
我认为 "protected" 事情与此有关;但如果我可以显示它,我可以 read/access 对吧?
如果你们需要整个数组(它很长)我可以把它放在这里。
谢谢。
I haven't seen an array like this
它是一个对象数组。学习一些关于 OOP 的知识。
这应该有效:
echo $customerList[0]->derivedResources['cards'];
基于print_r
:
Array
(
[0] => Customer Object
(
[status:protected] =>
[creation_date:protected] => 2016-01-14T12:07:07-06:00
[balance:protected] =>
[clabe:protected] => 321654qweasd
[derivedResources:protected] => Array
(
[cards] => 123123123123
//a lot of code
我们可以模拟:
<?php
$CustomerObject = new \stdClass;
$derivedResources = new \stdClass();
$CustomerObject->derivedResources = ["cards" => 123123123123];
$customerList = [$CustomerObject];
// print_r($customerList);
echo $customerList[0]->derivedResources['cards'];
其中,取消注释 print_r
结果:
Array
(
[0] => stdClass Object
(
[derivedResources] => Array
(
[cards] => 123123123123
)
)
)
123123123123