3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( array( 'id' => '2', 'name' => 'Item2', 'children' => array( array( 'id' => '1', 'name' => 'Item1', 'children' => array( array('id' => '5', 'name' => 'Item5') ) ), array( 'id' => '4', 'name' => 'Item4' ) ) ), array( 'id' => '3', 'name' => 'Item3' ) ); function list_items($array, $parent = 0) { $output = array(); foreach ($array as $arr) { $output[] = array('id' => $arr['id'], 'name' => $arr['name'], 'parent' => $parent); if (is_array($arr['children'] ?? NULL)) { $output = array_merge($output, list_items($arr['children'], $arr['id'])); } } return $output; } $items = list_items($array); print_r($items);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [id] => 2 [name] => Item2 [parent] => 0 ) [1] => Array ( [id] => 1 [name] => Item1 [parent] => 2 ) [2] => Array ( [id] => 5 [name] => Item5 [parent] => 1 ) [3] => Array ( [id] => 4 [name] => Item4 [parent] => 2 ) [4] => Array ( [id] => 3 [name] => Item3 [parent] => 0 ) )

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