3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Task 2: Parse the string * * Parse the $input string and build object tree that represents this structure: * https://drive.google.com/file/d/0BwhWcFzxN6_mZ2hkQlhZTnRrMDA/view?usp=sharing * Use Node class to build the tree and dump it to output * * Realize Node::dump() function and use it to output the tree in format: * A * B * C * C * C * B * C * C * A * B * B * C */ $input = 'A(B(CCC)B(CC))A(BB(C))'; class Node { public $letter; private $items = []; public function __construct($letter) { $this->letter = $letter; } public function addItem($item) { $this->items[] = $item; } public function dump($level = 0) { // write your code here... } } function createTree(string $input) { $jsonInput = $input; $jsonInput = str_replace(['(', ')'], ['[', ']'], $jsonInput); $jsonInput = preg_replace('~(\w)\[~', '"${1}":\[', $jsonInput); echo $jsonInput; } createTree($input);
Output for git.master, git.master_jit, rfc.property-hooks
"A":\["B":\[CCC]"B":\[CC]]"A":\[B"B":\[C]]

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:
58.37 ms | 401 KiB | 8 Q