How to show converted JSON PHP array in page -


i connecting api using curl turn array php array (i think). how can take array , put in page people view in more asthetically pleasing way (like variables).

array(2) { ["summonerid"]=> int(19975245) ["games"]=> array(10) { [0]=> array(14) { ["gameid"]=> int(1321012446) ["invalid"]=> bool(false) ["gamemode"]=> string(7) "classic" ["gametype"]=> string(12) "matched_game" ["subtype"]=> string(15) "ranked_solo_5x5" ["mapid"]=> int(1) ["teamid"]=> int(100) ["championid"]=> int(122) ["spell1"]=> int(14) ["spell2"]=> int(6) ["level"]=> int(30) ["createdate"]=> float(1395694236659) ["fellowplayers"]=> array(9) { [0]=> array(3) { ["summonerid"]=> int(43168746) ["teamid"]=> int(100) ["championid"]=> int(60) } [1]=> array(3) { ["summonerid"]=> int(47321626) ["teamid"]=> int(200) ["championid"]=> int(121) } [2]=> array(3) { ["summonerid"]=> int(21498881) ["teamid"]=> int(200) ["championid"]=> int(77) } [3]=> array(3) { ["summonerid"]=> int(23237414) ["teamid"]=> int(200) ["championid"]=> int(79) } [4]=> array(3) { ["summonerid"]=> int(25290254) ["teamid"]=> int(100) ["championid"]=> int(412) } [5]=> array(3) { ["summonerid"]=> int(32603601) ["teamid"]=> int(100) ["championid"]=> int(51) } [6]=> array(3) { ["summonerid"]=> int(9969) ["teamid"]=> int(200) ["championid"]=> int(25) } [7]=> array(3) { ["summonerid"]=> int(263293) ["teamid"]=> int(200) ["championid"]=> int(236) } [8]=> array(3) { ["summonerid"]=> int(19712716) ["teamid"]=> int(100) ["championid"]=> int(103) } } ["stats"]=> array(40) { ["level"]=> int(15) ["goldearned"]=> int(10708) ["numdeaths"]=> int(10) ["turretskilled"]=> int(1) ["minionskilled"]=> int(204) ["championskilled"]=> int(6) ["goldspent"]=> int(10915) ["totaldamagedealt"]=> int(131158) ["totaldamagetaken"]=> int(27011) ["killingsprees"]=> int(2) ["largestkillingspree"]=> int(2) ["team"]=> int(100) ["win"]=> bool(false) ["neutralminionskilled"]=> int(1) ["largestmultikill"]=> int(1) ["physicaldamagedealtplayer"]=> int(118328) ["magicdamagedealtplayer"]=> int(8277) ["physicaldamagetaken"]=> int(18495) ["magicdamagetaken"]=> int(7702) ["largestcriticalstrike"]=> int(548) ["timeplayed"]=> int(1764) ["totalheal"]=> int(2608) ["totalunitshealed"]=> int(1) ["assists"]=> int(5) ["item0"]=> int(1055) ["item1"]=> int(3078) ["item2"]=> int(3134) ["item3"]=> int(3265) ["item4"]=> int(3035) ["item6"]=> int(3340) ["sightwardsbought"]=> int(2) ["magicdamagedealttochampions"]=> int(2326) ["physicaldamagedealttochampions"]=> int(15107) ["totaldamagedealttochampions"]=> int(21586) ["truedamagedealtplayer"]=> int(4552) ["truedamagedealttochampions"]=> int(4152) ["truedamagetaken"]=> int(814) ["wardplaced"]=> int(9) ["neutralminionskilledenemyjungle"]=> int(1) ["totaltimecrowdcontroldealt"]=> int(219) } } [1]=> array(14) { ["gameid"]=> int(1320945501) ["invalid"]=> bool(false) 

and repeats few times different summoner id's , not.

the code used convert json php is:

<?php $url="api_link_here"; //  initiate curl $ch = curl_init(); // disable ssl verification curl_setopt($ch, curlopt_ssl_verifypeer, false); // return response, if false print response curl_setopt($ch, curlopt_returntransfer, true); // set url curl_setopt($ch, curlopt_url,$url); // execute $result=curl_exec($ch);  // dump beauty json :3 var_dump(json_decode($result, true)); ?> 

the original json array was:

{"summonerid":19975245,"games":[{"gameid":1320945501,"invalid":false,"gamemode":"classic","gametype":"matched_game","subtype":"ranked_solo_5x5","mapid":1,"teamid":200,"championid":106,"spell1":14,"spell2":6,"level":30,"createdate":1395691918584,"fellowplayers":[{"summonerid":22308749,"teamid":100,"championid":64},{"summonerid":19974069,"teamid":200,"championid":117},{"summonerid":43168746,"teamid":100,"championid":80},{"summonerid":22846462,"teamid":100,"championid":13},{"summonerid":32898052,"teamid":200,"championid":42},{"summonerid":40519573,"teamid":200,"championid":32},{"summonerid":29129833,"teamid":200,"championid":25},{"summonerid":22666731,"teamid":100,"championid":412},{"summonerid":165896,"teamid":100,"championid":51}],"stats":{"level":18,"goldearned":13451,"numdeaths":6,"turretskilled":1,"minionskilled":208,"championskilled":6,"goldspent":12235,"totaldamagedealt":135938,"totaldamagetaken":43804,"doublekills":1,"killingsprees":1,"largestkillingspree":3,"team":200,"win":true,"neutralminionskilled":14,"largestmultikill":2,"physicaldamagedealtplayer":66392,"magicdamagedealtplayer":65853,"physicaldamagetaken":30525,"magicdamagetaken":11895,"timeplayed":2098,"totalheal":3932,"totalunitshealed":1,"assists":8,"item0":1055,"item1":1011,"item2":3065,"item3":3143,"item4":3068,"item5":3265,"item6":3340,"magicdamagedealttochampions":7724,"physicaldamagedealttochampions":8310,"totaldamagedealttochampions":17663,"truedamagedealtplayer":3691,"truedamagedealttochampions":1629,"truedamagetaken":1384,"wardplaced":8,"neutralminionskilledenemyjungle":2,"neutralminionskilledyourjungle":12,"totaltimecrowdcontroldealt":1838}}, 

here's php code started. id's, you'll want pull in more data game's api can put name / friendly identifier id.

the json provided invalid, fixed :).

//json object obtained curl call. $json = ' {     "summonerid": 19975245,     "games": [         {             "gameid": 1320945501,             "invalid": false,             "gamemode": "classic",             "gametype": "matched_game",             "subtype": "ranked_solo_5x5",             "mapid": 1,             "teamid": 200,             "championid": 106,             "spell1": 14,             "spell2": 6,             "level": 30,             "createdate": 1395691918584,             "fellowplayers": [                 {                     "summonerid": 22308749,                     "teamid": 100,                     "championid": 64                 },                 {                     "summonerid": 19974069,                     "teamid": 200,                     "championid": 117                 },                 {                     "summonerid": 43168746,                     "teamid": 100,                     "championid": 80                 },                 {                     "summonerid": 22846462,                     "teamid": 100,                     "championid": 13                 },                 {                     "summonerid": 32898052,                     "teamid": 200,                     "championid": 42                 },                 {                     "summonerid": 40519573,                     "teamid": 200,                     "championid": 32                 },                 {                     "summonerid": 29129833,                     "teamid": 200,                     "championid": 25                 },                 {                     "summonerid": 22666731,                     "teamid": 100,                     "championid": 412                 },                 {                     "summonerid": 165896,                     "teamid": 100,                     "championid": 51                 }             ],             "stats": {                 "level": 18,                 "goldearned": 13451,                 "numdeaths": 6,                 "turretskilled": 1,                 "minionskilled": 208,                 "championskilled": 6,                 "goldspent": 12235,                 "totaldamagedealt": 135938,                 "totaldamagetaken": 43804,                 "doublekills": 1,                 "killingsprees": 1,                 "largestkillingspree": 3,                 "team": 200,                 "win": true,                 "neutralminionskilled": 14,                 "largestmultikill": 2,                 "physicaldamagedealtplayer": 66392,                 "magicdamagedealtplayer": 65853,                 "physicaldamagetaken": 30525,                 "magicdamagetaken": 11895,                 "timeplayed": 2098,                 "totalheal": 3932,                 "totalunitshealed": 1,                 "assists": 8,                 "item0": 1055,                 "item1": 1011,                 "item2": 3065,                 "item3": 3143,                 "item4": 3068,                 "item5": 3265,                 "item6": 3340,                 "magicdamagedealttochampions": 7724,                 "physicaldamagedealttochampions": 8310,                 "totaldamagedealttochampions": 17663,                 "truedamagedealtplayer": 3691,                 "truedamagedealttochampions": 1629,                 "truedamagetaken": 1384,                 "wardplaced": 8,                 "neutralminionskilledenemyjungle": 2,                 "neutralminionskilledyourjungle": 12,                 "totaltimecrowdcontroldealt": 1838             }         }     ] } '; //convert json object php associative array  $array = json_decode($json, true);  echo 'summoner: ' . $array['summonerid'] . '<br />'; //this counter loop, can game 1, game 2, etc... $i = 1; //loop through games foreach($array['games'] $game) {     echo '<h1>game ' . $i . '</h1>';      echo 'mode: ' . $game['gamemode'] . '<br />';      echo 'type: ' . $game['gametype'] . '<br />';      echo 'subtype: ' . $game['subtype'] . '<br />';      echo 'map: ' . $game['mapid'] . '<br />';      echo 'champion: ' . $game['championid'] . '<br />';       echo 'fellow players <br /><br />';     //under each game there array of players in game, let's loop on players     foreach($game['fellowplayers'] $player)     {         echo 'player id: ' . $player['summonerid'] . '<br />';         echo 'team: ' . $player['teamid'] . '<br /><br />';     }      echo '<hr />';      $i++; } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -