我有这个多维json数组
Array(
[LogicTokenList] => Array
(
[0] => Array
(
[position] => 0
[lemma] => accendi
[generalLemma] => accendere
[extendedPOSTag] => VER:impr+pres+2+s
[simplifiedPOSTag] => VER
[rearrangedTag] => VER
[retrievedRearrangedLemma] => accendere
[synonymProxyTag] => v.
[schankDependency] => ATRANS
[logicAnalysis] =>
[isWH] =>
[WHVariant] =>
[hyperonym] =>
[isFirstSubject] =>
[isFirstObject] =>
[substantivization] => accensione
[synonyms] => Array
(
[0] => appiccare il fuoco
[1] => attizzare
[2] => bruciare
[3] => incendiare
[4] => infiammare
)
)
[1] => Array
(
[position] => 1
[lemma] => la
[generalLemma] => la
[extendedPOSTag] => ART-F:s
[simplifiedPOSTag] => ART
[rearrangedTag] => ART
[retrievedRearrangedLemma] => la
[synonymProxyTag] => ART
[schankDependency] => 0
[logicAnalysis] =>
[isWH] =>
[WHVariant] =>
[hyperonym] =>
[isFirstSubject] =>
[isFirstObject] =>
[substantivization] =>
[synonyms] => Array
(
[0] => la
)
)
[2] => Array
(
[position] => 2
[lemma] => luce
[generalLemma] => Luce
[extendedPOSTag] => NPR
[simplifiedPOSTag] => NPR
[rearrangedTag] => NOU
[retrievedRearrangedLemma] => luce
[synonymProxyTag] => sost.
[schankDependency] => 0
[logicAnalysis] => COMP_OGG
[isWH] =>
[WHVariant] =>
[hyperonym] => ARTEFATTO
[isFirstSubject] =>
[isFirstObject] => 1
[substantivization] =>
[synonyms] => Array
(
[0] => baleno
[1] => fulgore
[2] => lampo
[3] => raggio
)
)
[3] => Array
(
[position] => 3
[lemma] => della
[generalLemma] => della
[extendedPOSTag] => ARTPRE-F:s
[simplifiedPOSTag] => ARTPRE
[rearrangedTag] => ARTPRE
[retrievedRearrangedLemma] => della
[synonymProxyTag] => ARTPRE
[schankDependency] => 0
[logicAnalysis] =>
[isWH] =>
[WHVariant] =>
[hyperonym] =>
[isFirstSubject] =>
[isFirstObject] =>
[substantivization] =>
[synonyms] => Array
(
[0] => della
)
)
[4] => Array
(
[position] => 4
[lemma] => cucina
[generalLemma] => cucina
[extendedPOSTag] => NOUN-F:s
[simplifiedPOSTag] => NOU
[rearrangedTag] => NOU
[retrievedRearrangedLemma] => cucina
[synonymProxyTag] => sost.
[schankDependency] => 0
[logicAnalysis] => COMP_SLUOGO
[isWH] =>
[WHVariant] =>
[hyperonym] => EDIFICIO
[isFirstSubject] =>
[isFirstObject] =>
[substantivization] =>
[synonyms] => Array
(
[0] => arte culinaria
[1] => gastronomia
)
)
[5] => Array
(
[position] => 5
[lemma] => alle
[generalLemma] => alla
[extendedPOSTag] => ARTPRE-F:p
[simplifiedPOSTag] => ARTPRE
[rearrangedTag] => ARTPRE
[retrievedRearrangedLemma] => alla
[synonymProxyTag] => ARTPRE
[schankDependency] => 0
[logicAnalysis] =>
[isWH] =>
[WHVariant] =>
[hyperonym] =>
[isFirstSubject] =>
[isFirstObject] =>
[substantivization] =>
[synonyms] => Array
(
[0] => alla
)
)
[6] => Array
(
[position] => 6
[lemma] => 20
[generalLemma] => 20
[extendedPOSTag] => NPR
[simplifiedPOSTag] => NPR
[rearrangedTag] => NPR
[retrievedRearrangedLemma] => 20
[synonymProxyTag] => Numero
[schankDependency] => 0
[logicAnalysis] => COMP_TEMPO
[isWH] =>
[WHVariant] =>
[hyperonym] =>
[isFirstSubject] =>
[isFirstObject] =>
[substantivization] =>
[synonyms] => Array
(
[0] => 20
)
)
)
[ChosenWHCategory] => ARTEFATTO
[GrammarAnalysisExecutionTime] => 2531
[LogicAnalysisExecutionTime] => 459
)
我已经用$json = json_decode($mydata, true);
解码了但是现在我需要在这个数组中搜索,例如,如果我在[simplfiedpostag]中找到值"VER",我需要打印[retrievedRearrangedLemma]。重要的是,这个数组的位置可能会改变。
可以将数组传递给递归函数
function search_array($arr = array()) {
if (!is_array($arr))
return;
foreach ($arr as $k => $v) {
search_arr($v);
if ($k == "simplifiedPOSTag"
&& strpos("VER", $v) !== false
&& !empty($arr["retrievedRearrangedLemma"])) {
echo $arr["retrievedRearrangedLemma"];
}
}
}
我不确定这是否是你需要的,试试这个:
for($i=0; $i<sizeof($json[LogicTokenList]); $i++) {
if($json[LogicTokenList][$i][simplifiedPOSTag]=='VER') echo $json[LogicTokenList][$i][retrievedRearrangedLemma];
}