Issue I have now is that the JSON data has an array within "trafficdata" I am unable to loop through it, any ideas?
//decoding the above JSON string
$json = json_decode($response,true);
$Name = $json['Data']['Name'];
$RouterIP = $json['Data']['RouterIP'];
// Get main Info
echo $Name."<br>";
echo $RouterIP."<br>";
// Get Traffic Info
$trafficdata = $json['Data']['trafficdata'];
print_r($trafficdata);
// Loop through Traffic Array
foreach($json['Data']['trafficdata'] as $key => $traffic) {
echo $traffic['Traffic IN']."<Br>";
}
When I do a print_r I get the following array
Array ( [0] => Array ( [0] => Traffic IN [1] => 0.06 % [2] => 0.02 [3] => 155.52 MB [4] => 0.12% [5] => 0.03% [6] => 0.01% ) [1] => Array ( [0] => Traffic OUT [1] => 0.03 % [2] => 0.01 [3] => 74.58 MB [4] => 0.04% [5] => 0.02% [6] => 0.00% ) )
Is there a better way than this to get the data?
// Loop through Traffic Array
foreach($json['Data']['trafficdata'] as $traffic) {
echo $traffic[0]." | ".$traffic[1]." | ".$traffic[3]." | ".$traffic[4]." | ".$traffic[5]." | ".$traffic[6]."<Br>";
}