I want to echo an array data from json decode result, so I have tried both the file_get_contents and also curl which works.
This is the response I get from the server which is json output..
{"Servers": {
"lastChangedDate": null,
"ServersList": [
{
"online": "The server is UP",
"offline": "The server is DOWN",
"maintainace": "The server is currently in maintenance mode",
"location": "EU",
"ip": "x.x.x.x"
},
{
"online": "The server is UP",
"offline": "The server is DOWN",
"maintainace": "The server is currently in maintenance mode",
"location": "US",
"ip": "x.x.x.x"
}
]
}}
now then the output will be an array like this after decoding it..
Array (
[Servers] => Array (
[lastChangedDate] =>
[ServersList] => Array (
[0] => Array (
[online] => The server is UP
[offline] => The server is down
[maintenance] => The server is currently in maintenance mode
[location] => EU
[ip] => x.x.x.x
)
[1] => Array (
[online] => The server is UP
[offline] => The server is DOWN
[maintenance] => The server is currently in maintenance mode
[location] => US
[ip] => x.x.x.x
)
)
)
)
Here is my php code
<?php
$request = file_get_contents("test.json");
$input = json_decode($request, true);
echo $input['Servers']['lastChangedDate']['ServersList'][0]['online'];
?>
demo with print_r ($input); instead of echo http://phpad.org/run/1666334020
So in my main page I want to output to be like this http://codepen.io/anon/pen/jEEPMG.html
$input['Servers']['ServersList'][0]['online'];should work