3v4l.org

run code in 300+ PHP versions simultaneously
x = SELECT t.titulo as categoria, tb2.titulo as produto FROM categoria LEFT JOIN tb2 ON tb2.id_cat = categoria.id ORDER BY t.titulo ASC <?php $x = array( array('categoria' => 'cat1', 'titulo' => 'prod1'), array('categoria' => 'cat1', 'titulo' => 'prod2'), array('categoria' => 'cat2', 'titulo' => 'prod3'), array('categoria' => 'cat3', 'titulo' => NULL) ); ?> <div class="wrapper"> <?php $previousCat = ''; foreach($x as $produto){ if ($previousCat != $produto['categoria']){ if ($previousCat != '') echo "</div>"; echo "<div class='cell'><h1>" . $produto['categoria'] . "</h1>"; $previousCat = $produto['categoria']; } echo "<span>" . $produto['titulo'] . "</span>"; } if ($previousCat != '') echo "</div>"; ?> </div> <style> .wrapper{ display: table; } .cell { display: table-cell; border: 1px solid red; padding: 10px; text-align: center; } .cell span { display: block; } </style>
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
x = SELECT t.titulo as categoria, tb2.titulo as produto FROM categoria LEFT JOIN tb2 ON tb2.id_cat = categoria.id ORDER BY t.titulo ASC <div class="wrapper"> <div class='cell'><h1>cat1</h1><span>prod1</span><span>prod2</span></div><div class='cell'><h1>cat2</h1><span>prod3</span></div><div class='cell'><h1>cat3</h1><span></span></div></div> <style> .wrapper{ display: table; } .cell { display: table-cell; border: 1px solid red; padding: 10px; text-align: center; } .cell span { display: block; } </style>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 x = SELECT t.titulo as categoria, tb2.titulo as produto FROM categoria LEFT JOIN tb2 ON tb2.id_cat = categoria.id ORDER BY t.titulo ASC <div class="wrapper"> <div class='cell'><h1>cat1</h1><span>prod1</span><span>prod2</span></div><div class='cell'><h1>cat2</h1><span>prod3</span></div><div class='cell'><h1>cat3</h1><span></span></div></div> <style> .wrapper{ display: table; } .cell { display: table-cell; border: 1px solid red; padding: 10px; text-align: center; } .cell span { display: block; } </style>

preferences:
241.91 ms | 403 KiB | 288 Q