[英]Getting a While loop with cURL?
I am currently working on a new project, only I am stuck at the part that i can't find a way to put a list of players with the info I wanna show...我目前正在从事一个新项目,只是我被困在我无法找到一种方法来放置玩家列表以及我想显示的信息的部分...
I currently have this:我目前有这个:
JSON DATA: JSON 数据:
participants
0
teamId 100
championId 18
summonerName "BlackedByLucian"
summonerId 23687629
1 {…}
2 {…}
3 {…}
4 {…}
5 {…}
6 {…}
7 {…}
8 {…}
9 {…}
PHP PHP
//GET CURRENT GAME DATA
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$get_game=curl_exec($ch);
curl_close($ch);
$get_game = json_decode($get_game, true);
//PLAYER DATA
$PlayerName = $get_game['participants'][0]['summonerName'];
$PlayerTeam = $get_game['participants'][0]['teamId'];
$PlayerChampion = $get_game['participants'][0]['championId'];
And I want to show it like this:我想像这样展示它:
Player1 | 1 | 23
Player2 | 1 | 27
Player3 | 2 | 25
Player4 | 2 | 24
Player5 | 2 | 11
etc.
btw.顺便提一句。 the 0 in
$get_game variable
means the player id of the json. $get_game variable
的 0 表示 json 的玩家 ID。
You could do something along the lines of this, utilising a for
loop.您可以使用
for
循环来做类似的事情。 You could also use a foreach
loop, but I'm old school hehe.您也可以使用
foreach
循环,但我是老派,呵呵。
for($i = 0; $i < count($get_game["participants"]); $i++)
echo $get_game["participants"][$i]["summonerName"] . " | " . $get_game["participants"][$i]["teamId"] . " | " . $get_game["participants"][$i]["championId"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.