3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'children' => [ [ 'id' => 123, 'title' => 'test', 'children' => [ [ 'id' => 345, 'title' => 'test 1', 'children' => [], ], [ 'id' => 567, 'title' => 'test 2', 'children' => [ [ 'id' => 789, 'title' => 'test 3', 'children' => [], ], [ 'id' => 333, 'title' => 'tset 4', 'children' => [ [ 'id' => 222, 'title' => 'test 5', 'children' => [], ], [ 'id' => 111, 'title' => 'test 55', 'children' => [], ], [ 'id' => 444, 'title' => 'test 556', 'children' => [], ], [ 'id' => 666, 'title' => 'test44', 'children' => [], ], ], ], [ 'id' => '5556', 'identifier' => 'test 2', 'children' => [ [ 'id' => 888, 'title' => 'test 2', 'children' => [], ], [ 'id' => 255, 'title' => 'tset', 'children' => [], ], [ 'id' => 454, 'title' => 'warm-up-5837', 'children' => [], ], ], ], ], ], ], ], ], ]; function flattenTree(array $tree): array { $flat = []; foreach ($tree['children'] ?? [] as $child) { $flat[] = array_filter($child, 'is_scalar'); if (!empty($child['children'])) { array_push($flat, ...flattenTree($child, $flat)); } } return $flat; } var_export(flattenTree($array));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'id' => 123, 'title' => 'test', ), 1 => array ( 'id' => 345, 'title' => 'test 1', ), 2 => array ( 'id' => 567, 'title' => 'test 2', ), 3 => array ( 'id' => 789, 'title' => 'test 3', ), 4 => array ( 'id' => 333, 'title' => 'tset 4', ), 5 => array ( 'id' => 222, 'title' => 'test 5', ), 6 => array ( 'id' => 111, 'title' => 'test 55', ), 7 => array ( 'id' => 444, 'title' => 'test 556', ), 8 => array ( 'id' => 666, 'title' => 'test44', ), 9 => array ( 'id' => '5556', 'identifier' => 'test 2', ), 10 => array ( 'id' => 888, 'title' => 'test 2', ), 11 => array ( 'id' => 255, 'title' => 'tset', ), 12 => array ( 'id' => 454, 'title' => 'warm-up-5837', ), )

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