ddglk Posted July 7 Share Posted July 7 (edited) I can't figure out how to sort this Json to a php array. I can make it echo the eventID but i can't get the other sections for playerfirstname and bagson. Thank you $url = "https://api.iplayacl.com/api/v1/match-stats/eventid/167958/matchid/13/gameid/1"; //The url from where you are getting the contents $response = (file_get_contents($url)); //Converting in json string $obj = json_decode($response); echo $obj->{'eventID'}; echo "<br>"; echo $obj->{'event_name'}; Edited July 7 by ddglk Quote Link to comment https://forums.phpfreaks.com/topic/322194-sort-json-to-array/ Share on other sites More sharing options...
Barand Posted July 7 Share Posted July 7 Post the contents of $response. Quote Link to comment https://forums.phpfreaks.com/topic/322194-sort-json-to-array/#findComment-1629454 Share on other sites More sharing options...
ddglk Posted July 7 Author Share Posted July 7 {"eventID":"167958","matchID":"13","gameID":"1","week_id":1,"adminID":34312,"event_name":"Frazier Creek Brewery and Distillery week 26 Blind Draw","matchType":"D","bracketType":"D","eventGroupID":1,"eventGroupSubID":"L","eventGroupDesc":"ACL","matchStatus":5,"matchStatusDesc":"Match Completed","scoresheet":true,"homeTeamID":1,"awayTeamID":9,"homeTeamName":"Team 1","awayTeamName":"Team 9","winningTeam":-1,"courtid":1,"homeColor":"#2196F3","awayColor":"#F44336","currentRound":24,"homeScore":23,"awayScore":17,"homePlayerPoints":0,"awayPlayerPoints":0,"homeRoundScore":0,"awayRoundScore":0,"homeBagsThrown":4,"awayBagsThrown":4,"rounddesc":"","roundLimit":-1,"event_match_details":[{"teamid":9,"playerid":113258,"playerfirstname":"Erik","playerlastname":"Rose","playernickname":"","playerstate":"FL","playercity":"Port St Lucie","playerimage":"https://mysqlvm.blob.core.windows.net/acl-player-photos/IMG_0962-113258.jpeg ","playedinnings":12,"bagsin":1,"bagson":3,"bagsoff":0,"avgbagsin":"1.92","avgbagson":"1.33","totalbagsin":23,"totalbagson":16,"totalbagsoff":9,"totalbagsthrown":48,"teamhomeaway":"AWAY","scoringavg":"7.08","scoringpct":"81.25","rounds":12,"totalpts":85,"ptsperrnd":7.08,"opponentpts":92,"opponentptsperrnd":7.67,"diffperrnd":-0.58,"totalfourbaggers":0,"fourbaggerpct":0,"bagsinpct":47.92,"bagsonpct":33.33,"bagsoffpct":18.75},{"teamid":9,"playerid":123693,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","playernickname":"Ande","playerstate":"FL","playercity":"FORT PIERCE","playerimage":"https://mysqlvm.blob.core.windows.net/acl-player-photos/1st place as walker 5-15-23-123693.jpg ","playedinnings":12,"bagsin":2,"bagson":2,"bagsoff":0,"avgbagsin":"2.00","avgbagson":"1.92","totalbagsin":24,"totalbagson":23,"totalbagsoff":1,"totalbagsthrown":48,"teamhomeaway":"AWAY","scoringavg":"7.92","scoringpct":"97.92","rounds":12,"totalpts":95,"ptsperrnd":7.92,"opponentpts":94,"opponentptsperrnd":7.83,"diffperrnd":0.08,"totalfourbaggers":0,"fourbaggerpct":0,"bagsinpct":50,"bagsonpct":47.92,"bagsoffpct":2.08},{"teamid":1,"playerid":182175,"playerfirstname":"Robert","playerlastname":"Shouse","playernickname":"Robert","playerstate":"FL","playercity":"Port St. Lucie","playerimage":null,"playedinnings":12,"bagsin":3,"bagson":0,"bagsoff":1,"avgbagsin":"2.25","avgbagson":"1.08","totalbagsin":27,"totalbagson":13,"totalbagsoff":8,"totalbagsthrown":48,"teamhomeaway":"HOME","scoringavg":"7.83","scoringpct":"83.33","rounds":12,"totalpts":94,"ptsperrnd":7.83,"opponentpts":95,"opponentptsperrnd":7.92,"diffperrnd":-0.08,"totalfourbaggers":1,"fourbaggerpct":8.33,"bagsinpct":56.25,"bagsonpct":27.08,"bagsoffpct":16.67},{"teamid":1,"playerid":200988,"playerfirstname":"Nicholas","playerlastname":"Hoinig","playernickname":"Nick","playerstate":"FL","playercity":"Port Saint Lucie","playerimage":null,"playedinnings":12,"bagsin":2,"bagson":1,"bagsoff":1,"avgbagsin":"2.00","avgbagson":"1.67","totalbagsin":24,"totalbagson":20,"totalbagsoff":4,"totalbagsthrown":48,"teamhomeaway":"HOME","scoringavg":"7.67","scoringpct":"91.67","rounds":12,"totalpts":92,"ptsperrnd":7.67,"opponentpts":85,"opponentptsperrnd":7.08,"diffperrnd":0.58,"totalfourbaggers":1,"fourbaggerpct":8.33,"bagsinpct":50,"bagsonpct":41.67,"bagsoffpct":8.33}],"event_team_details":[{"playerid":182175,"teamid":1,"teamname":"Team 1"},{"playerid":200988,"teamid":1,"teamname":"Team 1"},{"playerid":113258,"teamid":9,"teamname":"Team 9"},{"playerid":123693,"teamid":9,"teamname":"Team 9"}],"event_match_inning_history":[{"inningno":1,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":1,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":1,"bagson":3,"bagsoff":0,"totalpoints":6,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":2,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":3,"bagson":0,"bagsoff":1,"totalpoints":9,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":2,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":3,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":3,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":4,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":3,"bagson":0,"bagsoff":1,"totalpoints":9,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":4,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":5,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":5,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":6,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":2,"bagson":0,"bagsoff":2,"totalpoints":6,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":6,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":7,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":0,"bagson":3,"bagsoff":1,"totalpoints":3,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":7,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":0,"bagson":2,"bagsoff":2,"totalpoints":2,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":8,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":8,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":9,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":9,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":3,"bagson":0,"bagsoff":1,"totalpoints":9,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":10,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":3,"bagson":0,"bagsoff":1,"totalpoints":9,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":10,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":11,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":11,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":12,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":1,"bagson":3,"bagsoff":0,"totalpoints":6,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":12,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":0,"bagson":4,"bagsoff":0,"totalpoints":4,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":13,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":13,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":14,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":14,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":15,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":1,"bagson":3,"bagsoff":0,"totalpoints":6,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":15,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":16,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":1,"bagson":2,"bagsoff":1,"totalpoints":5,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":16,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":0,"bagson":4,"bagsoff":0,"totalpoints":4,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":17,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":17,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":18,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":18,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":19,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":4,"bagson":0,"bagsoff":0,"totalpoints":12,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":19,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":0,"bagson":2,"bagsoff":2,"totalpoints":2,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":20,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":1,"bagson":2,"bagsoff":1,"totalpoints":5,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":20,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":1,"bagson":2,"bagsoff":1,"totalpoints":5,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":21,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":21,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":3,"bagson":1,"bagsoff":0,"totalpoints":10,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":22,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":22,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":23,"playerid":200988,"teamid":1,"playerfirstname":"Nicholas","playerlastname":"Hoinig","bagsin":0,"bagson":3,"bagsoff":1,"totalpoints":3,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":23,"playerid":113258,"teamid":9,"playerfirstname":"Erik","playerlastname":"Rose","bagsin":2,"bagson":1,"bagsoff":1,"totalpoints":7,"teamname":"Team 9","teamhomeaway":"AWAY"},{"inningno":24,"playerid":182175,"teamid":1,"playerfirstname":"Robert","playerlastname":"Shouse","bagsin":4,"bagson":0,"bagsoff":0,"totalpoints":12,"teamname":"Team 1","teamhomeaway":"HOME"},{"inningno":24,"playerid":123693,"teamid":9,"playerfirstname":"Wayne","playerlastname":"Anderson Sr.","bagsin":2,"bagson":2,"bagsoff":0,"totalpoints":8,"teamname":"Team 9","teamhomeaway":"AWAY"}],"event_match_inning_summary":[{"inningNo":1,"homeScore":1,"awayScore":0},{"inningNo":2,"homeScore":2,"awayScore":0},{"inningNo":3,"homeScore":3,"awayScore":0},{"inningNo":4,"homeScore":3,"awayScore":1},{"inningNo":5,"homeScore":3,"awayScore":2},{"inningNo":6,"homeScore":3,"awayScore":4},{"inningNo":7,"homeScore":4,"awayScore":4},{"inningNo":8,"homeScore":4,"awayScore":4},{"inningNo":9,"homeScore":5,"awayScore":4},{"inningNo":10,"homeScore":5,"awayScore":5},{"inningNo":11,"homeScore":5,"awayScore":7},{"inningNo":12,"homeScore":7,"awayScore":7},{"inningNo":13,"homeScore":7,"awayScore":7},{"inningNo":14,"homeScore":7,"awayScore":10},{"inningNo":15,"homeScore":7,"awayScore":11},{"inningNo":16,"homeScore":8,"awayScore":11},{"inningNo":17,"homeScore":9,"awayScore":11},{"inningNo":18,"homeScore":9,"awayScore":13},{"inningNo":19,"homeScore":19,"awayScore":13},{"inningNo":20,"homeScore":19,"awayScore":13},{"inningNo":21,"homeScore":19,"awayScore":13},{"inningNo":22,"homeScore":19,"awayScore":13},{"inningNo":23,"homeScore":19,"awayScore":17},{"inningNo":24,"homeScore":23,"awayScore":17}],"matchPlayInfo":{},"matchPlayScorebugFlag":false,"status":"OK","message":"Match Details based on eventID | matchID | gameID"} Quote Link to comment https://forums.phpfreaks.com/topic/322194-sort-json-to-array/#findComment-1629459 Share on other sites More sharing options...
maxxd Posted July 7 Share Posted July 7 Just a point of clarification, in this case json_decode is returning an object not an array. To access any of the values in the object, call the property key. For instance, to loop through the players you'd do this: foreach($obj->event_match_details as $detail){ echo "{$detail->playerfirstname} {$detail->playerlastname}" } Quote Link to comment https://forums.phpfreaks.com/topic/322194-sort-json-to-array/#findComment-1629461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.