douba5540 2017-08-18 12:13
浏览 14
已采纳

根据数组中的另一个元素选择数组中的元素[关闭]

I've the following array and I would like to select the tier and the rank of the array where queueType is equal to RANKED_FLEX_TT or RANKED_SOLO_5x5 or RANKED_FLEX_SR. How do I do this? I cannot do the following to select the RANKED_SOLO_5x5 as the array is displayed randomly. That is to say sometimes the queueType RANKED_SOLO_5x5 will be in the array [1] or in the array [2] and not always in the array [0]. So I cannot simply do this to find the tier and the rank where queueType is equal to RANKED_SOLO_5x5:

<?php echo $r1[0]["tier"].' '.$r1[0]["rank"]; ?>

Here is an example of the array:

Array
(
    [0] => Array
        (
            [leagueName] => Anivia's Hunters
            [tier] => GOLD
            [queueType] => RANKED_SOLO_5x5
            [rank] => IV
            [playerOrTeamId] => 19302018
            [playerOrTeamName] => AlLeXaNDeR
            [leaguePoints] => 55
            [wins] => 198
            [losses] => 185
            [veteran] => 1
            [inactive] => 
            [freshBlood] => 
            [hotStreak] => 
        )

    [1] => Array
        (
            [leagueName] => Yorick's Warmongers
            [tier] => GOLD
            [queueType] => RANKED_FLEX_TT
            [rank] => V
            [playerOrTeamId] => 19302018
            [playerOrTeamName] => AlLeXaNDeR
            [leaguePoints] => 0
            [wins] => 21
            [losses] => 13
            [veteran] => 
            [inactive] => 
            [freshBlood] => 1
            [hotStreak] => 
        )

    [2] => Array
        (
            [leagueName] => Yorick's Rageborn
            [tier] => SILVER
            [queueType] => RANKED_FLEX_SR
            [rank] => II
            [playerOrTeamId] => 19302018
            [playerOrTeamName] => AlLeXaNDeR
            [leaguePoints] => 100
            [wins] => 61
            [losses] => 56
            [veteran] => 1
            [inactive] => 
            [freshBlood] => 
            [hotStreak] => 
            [miniSeries] => Array
                (
                    [target] => 2
                    [wins] => 1
                    [losses] => 1
                    [progress] => LWN
                )

        )

)
  • 写回答

1条回答 默认 最新

  • dongshuql24533 2017-08-18 12:22
    关注

    Hope that will help you :

       foreach($array as $subArray){
         foreach($subArray as $key => $value){
           if($key === "queueType" and ($value === "RANKED_FLEX_TT" or $value === "RANKED_SOLO_5x5" or $value === "RANKED_FLEX_SR"))
                echo $item['tier'] . ' ' . $item['rank'] . '<br>'; 
         }  
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应