3v4l.org

run code in 300+ PHP versions simultaneously
<?php $combos = [ //Test case 1: normally written. ['FirstClass_1', 'FirstClass_2', 'FirstClass_3'], //Test case 2: swapped 'l' with 'C' inside 'FirstClass_1' to make it 'FirstlCass1'. ['FirstlCass_1', 'FirstClass_2', 'FirstClass_3'], //Test case 3: swapped positions. ['FirstClass_2', 'FirstClass_3', 'FirstlCass_1'] ]; class Node{ public $val; public $children; public $end_of_data; function __construct($val){ $this->val = $val; $this->children = []; $this->end_of_data = false; } } class DataManager{ private $root; private const INSERTED = 1; private const EXISTS = 2; function __construct(){ $this->root = new Node('~'); } public function putIfAbsent($data){ sort($data); // to make different combinations/anagrams of same values as one $node = $this->root; $status = self::EXISTS; foreach($data as $value){ if(!isset($node->children[$value])){ $node->children[$value] = new Node($value); $status = self::INSERTED; } $node = $node->children[$value]; } $node->end_of_data = true; return $status; } } $o = new DataManager(); foreach($combos as $combo){ var_dump($o->putIfAbsent($combo)); }
Output for git.master, git.master_jit, rfc.property-hooks
int(1) int(1) int(2)

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