3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setTier(array $nodes, $tier = 1) { return array_map(function ($node) use ($tier) { $node->tier = $tier; $node->children = setTier($node->children, $tier + 1); return $node; }, $nodes); } $structure = json_decode(' [{ "name": "a", "children": [{ "name": "c", "children": [{ "name": "e", "children": [{ "name": "g", "children": [] }] }, { "name": "f", "children": [] }] }, { "name": "d", "children": [{ "name": "h", "children": [] }] }] }, { "name": "b", "children": [] }] '); $structure = setTier($structure); print_r($structure); die;
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => stdClass Object ( [name] => a [children] => Array ( [0] => stdClass Object ( [name] => c [children] => Array ( [0] => stdClass Object ( [name] => e [children] => Array ( [0] => stdClass Object ( [name] => g [children] => Array ( ) [tier] => 4 ) ) [tier] => 3 ) [1] => stdClass Object ( [name] => f [children] => Array ( ) [tier] => 3 ) ) [tier] => 2 ) [1] => stdClass Object ( [name] => d [children] => Array ( [0] => stdClass Object ( [name] => h [children] => Array ( ) [tier] => 3 ) ) [tier] => 2 ) ) [tier] => 1 ) [1] => stdClass Object ( [name] => b [children] => Array ( ) [tier] => 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:
26.61 ms | 416 KiB | 5 Q