3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $data = array( 0 => array('title'=>'a', 'start_date'=>'2013/04/20', 'end_date'=>'2013/05/20'), 1 => array('title'=>'a', 'start_date'=>'2013/04/20', 'end_date'=>'2013/05/20'), 2 => array('title'=>'a', 'start_date'=>'2013/04/20', 'end_date'=>'2013/05/20'), 3 => array('title'=>'b', 'start_date'=>'2013/04/20', 'end_date'=>'2013/05/20'), 4 => array('title'=>'c', 'start_date'=>'2013/04/20', 'end_date'=>'2013/05/20'), 5 => array('title'=>'c', 'start_date'=>'2013/04/20', 'end_date'=>'2013/05/20'), ); // manipulate by array $data2 = array_group($data, 'title'); function array_group($input,$sortkey){ foreach ($input as $key=>$val) { $output[$val[$sortkey]][]=$val; } return $output; } ?> <!-- Asal --> <h1>Old</h1> <table class="table" border="1"> <tr> <td>Title</td> <td>Start Date</td> <td>End Date</td> </tr> <?php foreach($data as $k=>$v) { ?> <tr> <td><?php echo $v['title'] ?></td> <td><?php echo $v['start_date'] ?></td> <td><?php echo $v['end_date']?></td> </tr> <?php } ?> </table> <!-- Lepas dah manipulate --> <h1>Latest</h1> <table border="1"> <tr> <td>Title</td> <td>Start date</td> <td>End date</td> </tr> <?php foreach ($data2 as $key => $value): $rowspan=count($value); ?> <tr> <td rowspan="<?php echo $rowspan; ?>"><?php echo $key;?></td> <td><?php echo $value[0]['start_date']?></td> <td><?php echo $value[0]['end_date']?></td> </tr> <?php $i=1;while($i<$rowspan) { ?> <tr> <td><?php echo $value[$i]['start_date']?></td> <td><?php echo $value[$i]['end_date']?></td> </tr> <?php $i++;} ?> <?php endforeach ?> </table>
Output for 4.3.0 - 7.1.0
<!-- Asal --> <h1>Old</h1> <table class="table" border="1"> <tr> <td>Title</td> <td>Start Date</td> <td>End Date</td> </tr> <tr> <td>a</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>a</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>a</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>b</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>c</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>c</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> </table> <!-- Lepas dah manipulate --> <h1>Latest</h1> <table border="1"> <tr> <td>Title</td> <td>Start date</td> <td>End date</td> </tr> <tr> <td rowspan="3">a</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td rowspan="1">b</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td rowspan="2">c</td> <td>2013/04/20</td> <td>2013/05/20</td> </tr> <tr> <td>2013/04/20</td> <td>2013/05/20</td> </tr> </table>