这可能是我几个小时以来一直没有得到的一个显而易见的答案。所以从这个维基百科API查询我得到了这个回答
{"batchcomplete":"","continue":{"sroffset":1,"continue":"-||"},"query":{"searchinfo":{"totalhits":173918},"search":[{"ns":0,"title":"Google","snippet":"search engine, see Google Search. For other uses, see Google (disambiguation). Not to be confused with Goggle'u00a0or Googol. Google Inc. is an American","size":143977,"wordcount":13927,"timestamp":"2015-11-25T08:44:48Z"}]}}
我已经转换成这个php数组
Array
(
[batchcomplete] =>
[continue] => Array
(
[sroffset] => 1
[continue] => -||
)
[query] => Array
(
[searchinfo] => Array
(
[totalhits] => 173918
)
[search] => Array
(
[0] => Array
(
[ns] => 0
[title] => Google
[snippet] => search engine, see Google Search. For other uses, see Google (disambiguation). Not to be confused with Goggle or Googol. Google Inc. is an American
[size] => 143977
[wordcount] => 13927
[timestamp] => 2015-11-25T08:44:48Z
)
)
)
)
我正试图使用此代码从阵列中提取标题实体
echo $array->query->search->0->title;
我做错了什么?
您使用的是stdClass对象,
echo $array->query->search->0->title;
用[]
代替->
echo $array['query']['search'][0]['title'];