我的数组看起来像这样。 (见下面的代码)
假设我想在[visibiltiyindex]中访问[value]。 还有[pagerank]中的[value]。
我提出的代码:
print_r ($results->answer->{"0"}->visibilityindex->{"0"}->value);
print_r ($results->answer->[0]->visibilityindex->[0]->value);
print_r ($results->answer->visibilityindex->value);
上面的所有代码示例都不起作用。 我使用的是php 5.2,所以 array_map 和 array_column 对我不起作用。
我检查了this post和this one,但他们的方法对我来说都不适用,因为我的数组更加多维...特别是[0]让我感到恼火。
我的阵列:
stdClass Object
(
[api_key] => Array
(
[0] => json
)
[method] => Array
(
[0] => domain.overview
)
[answer] => Array
(
[0] => stdClass Object
(
[visibilityindex] => Array
(
[0] => stdClass Object
(
[domain] => spiegel.de
[date] => 2014-03-17T00:00:00+01:00
[value] => 372.4821 (I WANT THIS VALUE)
)
)
[pagerank] => Array
(
[0] => stdClass Object
(
[domain] => spiegel.de
[date] => 2008-07-26T00:00:00+02:00
[value] => 8 (I WANT THIS VALUE ALSO)
)
)
[pages] => Array
(
[0] => stdClass Object
(
[domain] => spiegel.de
[date] => 2014-03-17T00:00:00+01:00
[value] => 1130000
)
)
[age] => Array
(
[0] => stdClass Object
(
[domain] => spiegel.de
[value] => 1996-12-23T00:00:00+01:00
)
)
[kwcount.seo] => Array
(
[0] => stdClass Object
(
[domain] => spiegel.de
[date] => 2014-03-17T00:00:00+01:00
[value] => 199022
)
)
[kwcount.sem] => Array
(
[0] => stdClass Object
(
[domain] => spiegel.de
[date] => 2014-03-17T00:00:00+01:00
[value] => 317
)
)
)
)
[credits] => Array
(
[0] => stdClass Object
(
[used] => 6
)
)
)
我只能访问这两个值?它必须是一个循环吗?
答案 0 :(得分:0)
answer
和visibilityIndex
是数组,所以你需要这个:
$results->answer[0]->visibilityIndex[0]->value