感謝您花時間查看我的問題。JSON數組上的foreach循環
希望這是有道理...
進出口尋找從一個JSON數組中提取數據。
在下面的數組中,我想循環遍歷Response> data> bucket> Equippable> 1> items> 0>節點的節點選項卡,查看它是否處於活動狀態,以及它是否處於活動狀態。
問題是「節點」部分可以是兩種不同長度,本實施例中有12倍的結果,但下一個我的只有8等
對於固定的結果,我將利用本
foreach ($json['Response']['data']['buckets']['Equippable']['1']['items']['0']['nodes'] as $Talentnode) {
$nodeActive[] = $Talentnode['0']['isActivated'];
$nodeState[] = $Talentnode['0']['state'];
}
如何將我做foreach循環時,我不知道會有多少結果?
[Response] => Array
[data] => Array
[buckets] => Array
[Invisible] => Array
[Item] => Array
[Equippable] => Array
[0] => Array
[1] => Array
[items] => Array
[0] => Array
[itemHash] => 320170738
[bindStatus] => 0
[isEquipped] => 1
[itemInstanceId] => 6917529121839082505
[itemLevel] => 50
[stackSize] => 1
[qualityLevel] => 100
[stats] => Array
[primaryStat] => Array
[canEquip] => 1
[equipRequiredLevel] => 40
[unlockFlagHashRequiredToEquip] => 2166136261
[cannotEquipReason] => 0
[damageType] => 1
[damageTypeHash] => 3373582085
[damageTypeNodeIndex] => 5
[damageTypeStepIndex] => 0
[progression] => Array
[talentGridHash] => 2047220462
[nodes] => Array
[0] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 10
[hidden] =>
[nodeHash] => 0
[1] => Array
[isActivated] =>
[stepIndex] => 0
[state] => 9
[hidden] =>
[nodeHash] => 1
[2] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 10
[hidden] =>
[nodeHash] => 2
[3] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 10
[hidden] =>
[nodeHash] => 3
[4] => Array
[isActivated] =>
[stepIndex] => 0
[state] => 9
[hidden] =>
[nodeHash] => 4
[5] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 10
[hidden] =>
[nodeHash] => 5
[6] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 0
[hidden] =>
[nodeHash] => 6
[7] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 13
[hidden] => 1
[nodeHash] => 7
[8] => Array
[isActivated] =>
[stepIndex] => 0
[state] => 9
[hidden] =>
[nodeHash] => 8
[9] => Array
[isActivated] => 1
[stepIndex] => 0
[state] => 10
[hidden] =>
[nodeHash] => 9
[10] => Array
[isActivated] =>
[stepIndex] => 0
[state] => 9
[hidden] =>
[nodeHash] => 10
[11] => Array
[isActivated] =>
[stepIndex] => 0
[state] => 9
[hidden] =>
[nodeHash] => 11
[useCustomDyes] => 1
[artRegions] => Array
[isEquipment] => 1
[isGridComplete] => 1
[perks] => Array
[location] => 1
[transferStatus] => 1
[locked] => 1
[lockable] => 1
[objectives] => Array
[state] => 1
你的代碼工作正常的'node'數組中的元素的任何量。爲什麼你認爲那裏不會有更多或更少的價值......? – Enstage