3v4l.org

run code in 300+ PHP versions simultaneously
<?php $example = [ ['text' => 'a', 'children' => [ ['text' => 'b'], ['text' => 'c'], ['text' => 'd', 'children' => [ ['text' => 'e'], ['text' => 'f'], ['text' => 'g', 'children' => [ ['text' => 'h'], ['text' => 'i'], ['text' => 'j'], ]], ['text' => 'k'], ['text' => 'l'], ['text' => 'm'], ]], ['text' => 'n'], ['text' => 'o'], ['text' => 'p'], ]] ]; function listElements(array $input, $depth = 0) { end($input); $final = key($input); $n = count($input); foreach ($input as $key => $element) { echo $element['text']; echo ($key == $final) ? " last of $n," : ''; echo " depth $depth", PHP_EOL; if (isset($element['children'])) { listElements($element['children'], $depth + 1); } } } listElements($example);
Output for git.master, git.master_jit, rfc.property-hooks
a last of 1, depth 0 b depth 1 c depth 1 d depth 1 e depth 2 f depth 2 g depth 2 h depth 3 i depth 3 j last of 3, depth 3 k depth 2 l depth 2 m last of 6, depth 2 n depth 1 o depth 1 p last of 6, depth 1

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:
36.04 ms | 406 KiB | 5 Q