@33balabol

Как вывести массив из api?

По запросу в Api выводится следующее:

{ "error": "false", "response": [{ "id": 1, "game": "ETS2", "ip": "37.187.170.151", "port": 42860, "name": "Europe 1", "shortname": "EU #1", "online": true, "players": 738, "maxplayers": 2300, "speedlimiter": 1 }, { "id": 3, "game": "ETS2", "ip": "191.101.3.39", "port": 42860, "name": "United States", "shortname": "US 1", "online": true, "players": 9, "maxplayers": 1000, "speedlimiter": 1 }, { "id": 4, "game": "ETS2", "ip": "37.187.170.151", "port": 42880, "name": "Europe 2", "shortname": "EU 2", "online": true, "players": 1445, "maxplayers": 2300, "speedlimiter": 0 }]}

Как получить отдельно значения где "id": 1, "id": 3 и тд
  • Вопрос задан
  • 864 просмотра
Решения вопроса 1
yarkov
@yarkov
Помог ответ? Отметь решением.
<?php

$str = '{  
		"error":"false",
		"response":[  
			{  
				"id":1,
				"game":"ETS2",
				"ip":"37.187.170.151",
				"port":42860,
				"name":"Europe 1",
				"shortname":"EU #1",
				"online":true,
				"players":738,
				"maxplayers":2300,
				"speedlimiter":1
			},
			{  
				"id":3,
				"game":"ETS2",
				"ip":"191.101.3.39",
				"port":42860,
				"name":"United States",
				"shortname":"US 1",
				"online":true,
				"players":9,
				"maxplayers":1000,
				"speedlimiter":1
			},
			{  
				"id":4,
				"game":"ETS2",
				"ip":"37.187.170.151",
				"port":42880,
				"name":"Europe 2",
				"shortname":"EU 2",
				"online":true,
				"players":1445,
				"maxplayers":2300,
				"speedlimiter":0
			}
		]
}';

$json = json_decode($str, true);

echo $json['response'][0]['id']."<br>";
echo $json['response'][1]['id'];

?>
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Rou1997
@Rou1997
Вроде так:

$json = json_decode($str, true);

echo $json['response'][0]['id'];
echo $json['response'][1]['id'];
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 20:43
20000 руб./за проект
19 апр. 2024, в 20:11
500 руб./за проект