3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array2table($array, $recursive = false, $null = '&nbsp;') { // Sanity check if (empty($array) || !is_array($array)) { return false; } if (!isset($array[0]) || !is_array($array[0])) { $array = array($array); } // Start the table $table = "<table>\n"; // The header $table .= "\t<tr>"; // Take the keys from the first row as the headings foreach (array_keys($array[0]) as $heading) { $table .= '<th>' . $heading . '</th>'; } $table .= "</tr>\n"; // The body foreach ($array as $row) { $table .= "\t<tr>" ; foreach ($row as $cell) { $table .= '<td>'; // Cast objects if (is_object($cell)) { $cell = (array) $cell; } if ($recursive === true && is_array($cell) && !empty($cell)) { // Recursive mode $table .= "\n" . array2table($cell, true, true) . "\n"; } else { $table .= (strlen($cell) > 0) ? htmlspecialchars((string) $cell) : $null; } $table .= '</td>'; } $table .= "</tr>\n"; } $table .= '</table>'; return $table; } $obst = ['foo' => 'Apfel', 'bar' => 'Birne', 'baz' => [1,2,3]]; echo array2table($obst, true);
Output for git.master, git.master_jit, rfc.property-hooks
<table> <tr><th>foo</th><th>bar</th><th>baz</th></tr> <tr><td>Apfel</td><td>Birne</td><td> <table> <tr><th>0</th><th>1</th><th>2</th></tr> <tr><td>1</td><td>2</td><td>3</td></tr> </table> </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:
32.83 ms | 401 KiB | 8 Q