当前我从我的json
解码了这个Array
(
[summonerId] => 19936953
[modifyDate] => 1394886787000
[champions] => Array
(
[0] => Array
(
[id] => 76
[name] => Nidalee
[stats] => Array
(
[totalSessionsPlayed] => 1
[totalSessionsLost] => 1
[totalSessionsWon] => 0
[totalChampionKills] => 1
[totalDamageDealt] => 22680
[totalDamageTaken] => 12406
[mostChampionKillsPerSession] => 1
[totalMinionKills] => 14
[totalDoubleKills] => 0
[totalTripleKills] => 0
[totalQuadraKills] => 0
[totalPentaKills] => 0
[totalUnrealKills] => 0
[totalDeathsPerSession] => 6
[totalGoldEarned] => 5496
[mostSpellsCast] => 0
[totalTurretsKilled] => 0
[totalPhysicalDamageDealt] => 5232
[totalMagicDamageDealt] => 17447
[totalFirstBlood] => 0
[totalAssists] => 3
[maxChampionsKilled] => 1
[maxNumDeaths] => 6
)
)
[1] => Array
(
[id] => 36
[name] => DrMundo
[stats] => Array
(
[totalSessionsPlayed] => 1
[totalSessionsLost] => 1
[totalSessionsWon] => 0
[totalChampionKills] => 1
[totalDamageDealt] => 89170
[totalDamageTaken] => 20817
[mostChampionKillsPerSession] => 1
[totalMinionKills] => 152
[totalDoubleKills] => 0
[totalTripleKills] => 0
[totalQuadraKills] => 0
[totalPentaKills] => 0
[totalUnrealKills] => 0
[totalDeathsPerSession] => 3
[totalGoldEarned] => 8401
[mostSpellsCast] => 0
[totalTurretsKilled] => 0
[totalPhysicalDamageDealt] => 24456
[totalMagicDamageDealt] => 64544
[totalFirstBlood] => 0
[totalAssists] => 2
[maxChampionsKilled] => 1
[maxNumDeaths] => 3
)
)
[2] => Array
(
[id] => 115
[name] => Ziggs
[stats] => Array
(
[totalSessionsPlayed] => 2
[totalSessionsLost] => 2
[totalSessionsWon] => 0
[totalChampionKills] => 0
[totalDamageDealt] => 108574
[totalDamageTaken] => 12076
[mostChampionKillsPerSession] => 0
[totalMinionKills] => 187
[totalDoubleKills] => 0
[totalTripleKills] => 0
[totalQuadraKills] => 0
[totalPentaKills] => 0
[totalUnrealKills] => 0
[totalDeathsPerSession] => 3
[totalGoldEarned] => 9138
[mostSpellsCast] => 0
[totalTurretsKilled] => 0
[totalPhysicalDamageDealt] => 9926
[totalMagicDamageDealt] => 98510
[totalFirstBlood] => 0
[totalAssists] => 2
[maxChampionsKilled] => 0
[maxNumDeaths] => 2
)
)
[3] => Array
(
[id] => 254
[name] => Vi
[stats] => Array
(
[totalSessionsPlayed] => 4
[totalSessionsLost] => 3
[totalSessionsWon] => 1
[totalChampionKills] => 10
[totalDamageDealt] => 360858
[totalDamageTaken] => 63341
[mostChampionKillsPerSession] => 5
[totalMinionKills] => 127
[totalDoubleKills] => 0
[totalTripleKills] => 0
[totalQuadraKills] => 0
[totalPentaKills] => 0
[totalUnrealKills] => 0
[totalDeathsPerSession] => 10
[totalGoldEarned] => 30065
[mostSpellsCast] => 0
[totalTurretsKilled] => 0
[totalPhysicalDamageDealt] => 314488
[totalMagicDamageDealt] => 2988
[totalFirstBlood] => 0
[totalAssists] => 12
[maxChampionsKilled] => 5
[maxNumDeaths] => 5
)
)
)
现在我想知道的是有一种简单的方法可以显示所有变量,例如Totalsessionslost totalsessionsplayed并为每个数组执行此操作吗?
我试图通过使用Riot Games APi制作一个像lolking.net这样的网站,希望你们能帮助我们
问候
答案 0 :(得分:1)
考虑使用单个阵列:
$array = [1,2,3,4,5];
将其打印出来就像这样容易:
for($i = 0; $i < $array.length; $i++) {
print $array[$i]; //here I select the i-value in array, so if i = 2 the output will be 3
}
彼此之间的多个数组工作相同,只是它在循环中的循环
for($i......) {
print "first array value: ". $i;
for($o = 0; $o < $secondarray.length; $o++) {
print "second array value: ". $o;
}
}
将此与您所在的数据结构一起使用。
如果您需要在表格中使用此功能,则必须在print语句中添加html标记。尽管如此,请将变量保留在字符串(引号)之外。
即:
for($summonerIndex = 0; $summonerIndex < $mainArray.length; $summonerIndex++) {
$championArray = $mainArray[$i];
for($championIndex = 0; $championIndex < $championArray.length; $championIndex) {
$statsArray = $championArray[$o];
for($statsIndex = 0; $statsIndex < $statsArray.length; $statsIndex++) {
print "Value of statsarray: ". $statsArray[$statsIndex];
}
}
}
注意:这是未经测试的,可能包含错误。
答案 1 :(得分:0)
CakePHP框架中有一个“Set”类http://book.cakephp.org/2.0/en/core-utility-libraries/set.html 查看Set :: extract方法。