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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题