3v4l.org

run code in 300+ PHP versions simultaneously
<?php // result from query: SELECT * FROM depts $depts = array( array( // row #0 'deptid' => 1, 'dept_code' => '1', 'dept_name' => 'wadir Umum', 'parent_deptid' => 0, ), array( // row #1 'deptid' => 2, 'dept_code' => '101', 'dept_name' => 'bagian umum', 'parent_deptid' => 1, ), array( // row #2 'deptid' => 3, 'dept_code' => '10101', 'dept_name' => 'kepala umum', 'parent_deptid' => 2, ), array( // row #3 'deptid' => 4, 'dept_code' => '102', 'dept_name' => 'bagian privasi', 'parent_deptid' => 1, ), array( // row #4 'deptid' => 5, 'dept_code' => '1010101', 'dept_name' => 'SUb bagian Tu', 'parent_deptid' => 3, ), array( // row #5 'deptid' => 6, 'dept_code' => '1010102', 'dept_name' => 'bagian umum', 'parent_deptid' => 3, ), ); $nodes = array(); $roots = array(); // init nodes foreach ($depts as $dept) { $dept['childs'] = array(); // init childs $nodes[$dept['deptid']] = $dept; } foreach ($depts as $dept) { if ($dept['parent_deptid'] == 0) { $roots[] = $dept['deptid']; // add root } else { $nodes[$dept['parent_deptid']]['childs'][] = $dept['deptid']; // add to parents chlids list } } function getSubtreeHTMLList($deptsids, $nodes) { $result = '<ul>'; foreach ($deptsids as $deptsid) { $result .= '<li>'; $result .= $nodes[$deptsid]['dept_name']; if (count($nodes[$deptsid]['childs'] > 0)) { $result .= getSubtreeHTMLList($nodes[$deptsid]['childs'], $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/mnV5m:67 Stack trace: #0 /in/mnV5m(76): getSubtreeHTMLList(Array, Array) #1 {main} thrown in /in/mnV5m on line 67
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/mnV5m:67 Stack trace: #0 /in/mnV5m(76): getSubtreeHTMLList(Array, Array) #1 {main} thrown in /in/mnV5m on line 67
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:
101.32 ms | 407 KiB | 5 Q