php - 使用 cURL 获得 While 循环?
问题描述
我目前正在做一个新项目,只是我被困在我无法找到一种方法来放置包含我想要显示的信息的玩家列表的部分......
我目前有这个:
JSON数据:
participants
0
teamId 100
championId 18
summonerName "BlackedByLucian"
summonerId 23687629
1 {…}
2 {…}
3 {…}
4 {…}
5 {…}
6 {…}
7 {…}
8 {…}
9 {…}
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'];
我想这样展示它:
Player1 | 1 | 23
Player2 | 1 | 27
Player3 | 2 | 25
Player4 | 2 | 24
Player5 | 2 | 11
etc.
顺便提一句。0 in$get_game variable
表示 json 的玩家 ID。
解决方案
你可以按照这个思路做一些事情,利用一个for
循环。你也可以使用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"];
推荐阅读
- java - Zeppelin:Hive 解释器没有获取详细信息
- python - 从数据框列中删除部分字符串
- python - 与号被替换为逗号
- python - 如何使用循环从数据帧创建特定的 json 格式
- java - 将图像和文本添加到 android gridview
- java - 多个对象用于用于序列化 @RequestBody 的单例 bean
- sql - 来自具有公共列的两个表的不匹配记录
- excel - 当我只想将日期作为 X 轴时,为什么我将日期作为一系列数据?
- javascript - 有什么方法可以调用包含 it() 的 Mocha 函数并运行 `it` 中的任何内容?
- spring-boot - 控制器不允许请求发布,但可以正常工作