3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Fetch data from BD // $options = $stmt->query("SELECT * FROM Options")->fetch_all(PDO::FETCH_ASSOC); $options = [ ['id' => 1, 'name' => 'admin', 'ref' => 0], ['id' => 2, 'name' => 'A', 'ref' => 1], ['id' => 3, 'name' => 'B', 'ref' => 2], ['id' => 4, 'name' => 'C', 'ref' => 1], ['id' => 5, 'name' => 'D', 'ref' => 2], ['id' => 6, 'name' => 'E', 'ref' => 3], ['id' => 7, 'name' => 'F', 'ref' => 3], ['id' => 8, 'name' => 'G', 'ref' => 2], ]; $nodes = array(); $roots = array(); // init nodes indexed by IDs foreach ($options as $option) { $option['subIds'] = array(); // init subIds $nodes[$option['id']] = $option; } // build a recursive structure (by reference) foreach ($options as $option) { if ($option['ref'] == 0) { $roots[] = $option['id']; // add a root } else { $nodes[$option['ref']]['subIds'][] = $option['id']; // add a subnode } } // build recursive HTML-List function getSubtreeHTMLList($subOptionIds, $nodes) { $result = '<ul>'; foreach ($subOptionIds as $optionsId) { $result .= '<li>'; $result .= $nodes[$optionsId]['name']; if (count($nodes[$optionsId]['subIds'] > 0)) { $result .= getSubtreeHTMLList($nodes[$optionsId]['subIds'], $nodes); } $result .= '</li>'; } $result .= '</ul>'; return $result; } echo getSubtreeHTMLList($roots, $nodes); ?>
Output for git.master, git.master_jit
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /in/Q7X8F:43 Stack trace: #0 /in/Q7X8F(52): getSubtreeHTMLList(Array, Array) #1 {main} thrown in /in/Q7X8F on line 43
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, true given in /in/Q7X8F:43 Stack trace: #0 /in/Q7X8F(52): getSubtreeHTMLList(Array, Array) #1 {main} thrown in /in/Q7X8F on line 43
Process exited with code 255.

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:
28.72 ms | 407 KiB | 5 Q