3v4l.org

run code in 500+ PHP versions simultaneously
<?php function showCell($cell, $isHeader, $selectedTitle) { echo '<td>'; if ($selectedTitle || $isHeader) { echo htmlspecialchars($cell); } else { echo sprintf('<a href="?title=%1$s">%1$s</a>', htmlspecialchars($cell)); } echo '</td>', PHP_EOL; } function showRow($cellsToShow, $isHeader, $selectedTitle) { if ($isHeader) { echo '<thead>', PHP_EOL; } echo '<tr>', PHP_EOL; foreach ($cellsToShow as $cell) { showCell($cell, $isHeader, $selectedTitle); } echo '</tr>', PHP_EOL; if ($isHeader) { echo '</thead>', PHP_EOL; } } function showTable($handle, $selectedTitle) { $idx = 0; echo '<table>', PHP_EOL; while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { // If we're on the first row which holds titles, always show. // Also, if the user selected a title, and it matches this row's title, show it. if(0 !== $idx && $selectedTitle && $row[0] !== $selectedTitle){ continue; } // cellsToShow is always an array. If we're showing based on a selection, it is everything. // Otherwise, it will be an array of just the first cell. This last seems weird, but it // allows the showRow method to not concern itself with higher level logic. $cellsToShow = $selectedTitle ? $row : [$row[0]]; showRow($cellsToShow, $idx++ === 0, $selectedTitle); } echo '</table>', PHP_EOL; } // Mock a CSV file in memory for demo purposes $handle = fopen('php://memory', 'rb+'); fwrite($handle, "Title,Author,Year\nBook 1,Alice,2020\nBook 2,Bob,2019\nBook 3,Charlie,1980"); rewind($handle); // Grab the title from the query string, default to null if not found $selectedTitle = $_GET['title'] ?? null; showTable($handle, $selectedTitle); fclose($handle);
Output for rfc.property-hooks, git.master_jit, git.master
<table> <thead> <tr> <td>Title</td> </tr> </thead> <tr> <td><a href="?title=Book 1">Book 1</a></td> </tr> <tr> <td><a href="?title=Book 2">Book 2</a></td> </tr> <tr> <td><a href="?title=Book 3">Book 3</a></td> </tr> </table>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
24.85 ms | 1158 KiB | 4 Q