3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 1 => [ 'categoryName'=>'Main One', 'title'=>'Title one', 'date'=>'2019-09-01', 'score'=>2500 ], 2 => [ 'categoryName'=>'Main One', 'title'=>'Title two', 'date'=>'2019-09-02', 'score'=>3000 ], 3 => [ 'categoryName'=>'Main Two', 'title'=>'Other title', 'date'=>'2019-09-02', 'score'=>2100 ], 4 => [ 'categoryName'=>'Main Three', 'title'=>'Other title', 'date'=>'2019-09-05', 'score'=>200 ], 5 => [ 'categoryName'=>'Main Three', 'title'=>'Other topic', 'date'=>'2019-09-02', 'score'=>1000 ] ]; $prevMain = ""; $currentMain = ""; $html = "<table border=1><tbody>"; foreach($array as $row): $currentMain = $row["categoryName"]; if($currentMain !== $prevMain) { $prevMain = $row["categoryName"]; $html .= '<tr>' . '<td colspan="2">' . $row['categoryName'] . '</td>' . '<td></td>' . '</tr>'; } $html .='<tr>'. '<td>'.$row['date'] .'</td>'. '<td>'.$row['title'].'</td>'. '<td>'.$row['score'] . '</td>'. '</tr>'; endforeach; $html .= "</tbody></table>"; echo $html;
Output for 7.1.25 - 7.1.32, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
<table border=1><tbody><tr><td colspan="2">Main One</td><td></td></tr><tr><td>2019-09-01</td><td>Title one</td><td>2500</td></tr><tr><td>2019-09-02</td><td>Title two</td><td>3000</td></tr><tr><td colspan="2">Main Two</td><td></td></tr><tr><td>2019-09-02</td><td>Other title</td><td>2100</td></tr><tr><td colspan="2">Main Three</td><td></td></tr><tr><td>2019-09-05</td><td>Other title</td><td>200</td></tr><tr><td>2019-09-02</td><td>Other topic</td><td>1000</td></tr></tbody></table>
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
196.05 ms | 407 KiB | 5 Q