php - Searching through multidimensional array to get information? -


i working on multidimensional array shows information riotgames's (the creators of league of legends) api. request api searched username , summonerid (playerid) returns information looks :

array ( [summonerid] => 34943406 [playerstatsummaries] =>  array (  [0] => array ( [playerstatsummarytype] => aramunranked5x5 [wins] => 273 [modifydate] => 1416009440000 [aggregatedstats] => array ( [totalchampionkills] => 5808 [totalturretskilled] => 298 [totalassists] => 9025 ) )  [1] => array ( [playerstatsummarytype] => ascension [wins] => 2 [modifydate] => 1415466770000 [aggregatedstats] => array ( ) )  [2] => array ( [playerstatsummarytype] => cap5x5 [wins] => 41 [modifydate] => 1416177610000 [aggregatedstats] => array ( [totalchampionkills] => 562 [totalminionkills] => 9087 [totalturretskilled] => 79 [totalneutralminionskilled] => 2371 [totalassists] => 475 ) )  

and goes on, depending on how many gamemodes player has played. every gamemode starts number [1/2/3], not same every user, depending on gamemodes have played.

my question how search through array find "cap5x5" example , take out stats display them in clean-looking table stats. problem account, gamemode "rankedsolo5x5" on [9] friend's account on [7]. vague question kinda hard explain.

assuming cap5x5 found in playerstatsummarytype

<?php //(...)some code might have before table...  function returntable($array, $searchfor) {   $content = '<table>';   foreach($array['playerstatsummaries'] $playerstat) {      if($playerstat['playerstatsummarytype'] == $searchfor) {          $content .= '<tr>';              $content .= '<td>wins</td><td>' . $playerstat['wins'] . '</td>';              $content .= '<td>totalchampionkills</td><td>' . $playerstat['aggregatedstats']['totalchampionkills'] . '</td>';              $content .= '<td>totalminionkills</td><td>' . $playerstat['aggregatedstats']['totalminionkills'] . '</td>';              $content .= '<td>totalturretskilled</td><td>' . $playerstat['aggregatedstats']['totalturretskilled'] . '</td>';              $content .= '<td>totalneutralminionskilled</td><td>' . $playerstat['aggregatedstats']['totalneutralminionskilled'] . '</td>';              $content .= '<td>totalassists</td><td>' . $playerstat['aggregatedstats']['totalassists'] . '</td>';           $content .= '</tr>';      } else {          echo 'error: stats not found game mode. try different one';          continue;      }   }    $content .= '</table>';    return $content; }  echo returntable($array, 'cap5x5'); //or... echo returntable($array, 'whatevergameyouwant'); //or... echo returntable($array, $gamemode); //if $gamemode = 'cap5x5' (for example...) 

hope helps! :d


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -