3v4l.org

run code in 300+ PHP versions simultaneously
<?php $gallery = [ (object) ['path' => 'imgs/img_a.jpg'], (object) ['path' => 'imgs/img_b.png'], (object) ['path' => 'imgs/img_c.jpeg'], (object) ['path' => 'imgs/img_d.gif'], ]; $template = <<<HTML <tr> <td>%s</td> <td>%s</td> <td>%s</td> <tr> HTML; echo '<table border="1">'; foreach (array_chunk($gallery, 3) as $set) { printf( $template, "<img src=\"{$set[0]->path}\">", isset($set[1]) ? "<img src=\"{$set[1]->path}\">" : '', isset($set[2]) ? "<img src=\"{$set[2]->path}\">" : '' ); } echo "\n</table>";
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
<table border="1"> <tr> <td><img src="imgs/img_a.jpg"></td> <td><img src="imgs/img_b.png"></td> <td><img src="imgs/img_c.jpeg"></td> <tr> <tr> <td><img src="imgs/img_d.gif"></td> <td></td> <td></td> <tr> </table>

preferences:
61.9 ms | 402 KiB | 62 Q