我正在通过 Amazon API 访问产品详细信息,并在我的数据数组中获取此信息:
["BrowseNodes"]=>
array(1) {
["BrowseNode"]=>
array(3) {
[0]=>
array(3) {
["BrowseNodeId"]=>
string(10) "7421468011"
["Name"]=>
string(24) "Educational & Nonfiction"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(3) {
["BrowseNodeId"]=>
string(4) "4390"
["Name"]=>
string(14) "Graphic Novels"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(3) {
["BrowseNodeId"]=>
string(4) "4366"
["Name"]=>
string(23) "Comics & Graphic Novels"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(4) {
["BrowseNodeId"]=>
string(4) "1000"
["Name"]=>
string(8) "Subjects"
["IsCategoryRoot"]=>
bool(true)
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(2) {
["BrowseNodeId"]=>
string(6) "283155"
["Name"]=>
string(5) "Books"
}
}
}
}
}
}
}
}
}
[1]=>
array(3) {
["BrowseNodeId"]=>
string(5) "13871"
["Name"]=>
string(20) "History & Philosophy"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(3) {
["BrowseNodeId"]=>
string(2) "75"
["Name"]=>
string(14) "Science & Math"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(4) {
["BrowseNodeId"]=>
string(4) "1000"
["Name"]=>
string(8) "Subjects"
["IsCategoryRoot"]=>
bool(true)
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(2) {
["BrowseNodeId"]=>
string(6) "283155"
["Name"]=>
string(5) "Books"
}
}
}
}
}
}
}
[2]=>
array(3) {
["BrowseNodeId"]=>
string(5) "11256"
["Name"]=>
string(20) "Folklore & Mythology"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(3) {
["BrowseNodeId"]=>
string(5) "11232"
["Name"]=>
string(15) "Social Sciences"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(3) {
["BrowseNodeId"]=>
string(10) "3377866011"
["Name"]=>
string(26) "Politics & Social Sciences"
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(4) {
["BrowseNodeId"]=>
string(4) "1000"
["Name"]=>
string(8) "Subjects"
["IsCategoryRoot"]=>
bool(true)
["Ancestors"]=>
array(1) {
["BrowseNode"]=>
array(2) {
["BrowseNodeId"]=>
string(6) "283155"
["Name"]=>
string(5) "Books"
}
}
}
}
}
}
}
}
}
</pre>
关键是我需要在这个例子中提取价值“政治与社会科学”,深度并不总是相同的。然而,每个数组从头到尾都是一样的 - 书籍 -> 主题 -> 政治与社会科学
由于我通过脚本运行了数百本书,因此我需要自动化的方式来从底部获得第三级。它始终是数组末尾的第 3 级。