Forum Moderators: coopster
$light = '#fff';
$tint = '#c0c0c0';
$bg=null;
<?php
$json=file_Get_contents("new.json");
$jsonIterator = new
RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST); // multiple lines only for this forum
if (count($jsonIterator) > 0) {
echo "<table border=\"1\">\n";
foreach ($jsonIterator as $key => $val) {
$bg = ($bg==$light)?$tint:$light;
if(is_array($val)) {
echo "<tr><td style=\"background:$bg\" colspan=\"2\">$key</td> </tr>\n";
}
// If it's a **list** array, this might be better - remove the above and uncomment this. If
// it's an associative array, you'll neet to do the
// same thing you're doing in the outer loop:
//if(is_array($val)) {
// $cnt = count($val);
// echo "<tr><td style=\"background:$bg\">$key</td><td>";
// for ($j=0;$j<$cnt;$j++) { echo " " . $val[$j]; }
// echo "</td></tr>\n";
//}
else {
echo "<tr><td style=\"background:$bg\">$key</td><td style=\"background:$bg\">$val</td></tr>\n";
}
}
echo "</table>\n\n";
}
else { echo "<p>The iterator is empty.</p>"; }
?>