Answer the question
In order to leave comments, you need to log in
how to get array from api?
Upon request, the Api displays the following:
{ "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 }]}
How to get separate values where "id": 1, "id": 3 and so on
Answer the question
In order to leave comments, you need to log in
<?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'];
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question