3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $result = array( 'Date 1' => array ( 'Object 1 ' => array ( 'Field 1' => "Value 1", 'Field 2' => "Value 2", 'Field 3' => "Value 3", ), ), 'Date 2' => array ( 'Object 1 in Date 2' => array ( 'Field 1' => "Value 1", 'Field 2' => "Value 2", ), 'Object 2 in Date 2' => array ( 'Field 1' => "Value 1", 'Field 2' => "Value 2", 'Field 3' => "Value 3", ), ), ); function count_childs($parent_array,$total = 0) { if(is_array($parent_array)) { foreach ($parent_array as $key => $value) { if(is_array($value)){ $total += count($value); count_childs($value,$total); } else $total += 1; } } return $total; } $firstField =false; $first = false; echo '<div>'; echo '<table id="r" border=1>'; echo '<tr>'; echo '<th>Date</th>'; echo '<th>Object Type</th>'; echo '<th>Field</th>'; echo '<th>Count</th>'; echo '</tr>'; foreach ($result as $key=>$value){ echo "<tr>"; $date_rowspan = count_childs($value); echo "<td rowspan= $date_rowspan>$key</td>"; foreach ($value as $key1 => $value1) { $obj_rowspan = count_childs($value1); echo "<td rowspan= $obj_rowspan>$key1</td>"; echo $first_row = true; foreach ($value1 as $key2 => $value2) { if($first_row){ echo "<td>$key2</td><td>$value2</td></tr>"; $first_row = false; } else echo "<td>$key2</td><td>$value2</td><tr>"; } } echo "</tr>"; } echo '</table>';
Output for 4.3.0 - 5.6.30, hhvm-3.10.1 - 3.17.3, 7.0.0 - 7.2.8
<div><table id="r" border=1><tr><th>Date</th><th>Object Type</th><th>Field</th><th>Count</th></tr><tr><td rowspan= 3>Date 1</td><td rowspan= 3>Object 1 </td>1<td>Field 1</td><td>Value 1</td></tr><td>Field 2</td><td>Value 2</td><tr><td>Field 3</td><td>Value 3</td><tr></tr><tr><td rowspan= 5>Date 2</td><td rowspan= 2>Object 1 in Date 2</td>1<td>Field 1</td><td>Value 1</td></tr><td>Field 2</td><td>Value 2</td><tr><td rowspan= 3>Object 2 in Date 2</td>1<td>Field 1</td><td>Value 1</td></tr><td>Field 2</td><td>Value 2</td><tr><td>Field 3</td><td>Value 3</td><tr></tr></table>