3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { public $tree; private $failure = false; public function __construct() { // First element of the array represents the name of the category, so to iterate children, we have to go from index 1 $tree = $this->tree; $tree["root"] = array(); } private function &getCategoryWithNameInSubtree($name, &$subTreeRoot) { if (count($subTreeRoot) == 0) return $this->failure; // There are no branches coming from this root // So, the subtree has some branches to traverse... foreach ($subTreeRoot as $branchName => &$branch) { if ($branchName == $name) { // Search is over - this branch has the specified name return $branch; } else { $subTreeSearchResult = $this->getCategoryWithNameInSubtree($name, $branch); if($subTreeSearchResult) { return $subTreeSearchResult; } else { //If we have reached this, it means the name was not found in that branch } } } //We traversed all branches and no name was equal to the specified name return $this->failure; } public function &getCategoryWithName($name) { $tree = &$this->tree; return $this->getCategoryWithNameInSubtree($name, $tree); } } $c = new CategoryTree(); $c->tree=array("prima" => array("prima-prima" => [], "prima-seconda" => [], "prima-terza" => []), "seconda" => array("seconda-prima" => [], "seconda-seconda" => [], "seconda-terza" => []), "terza" => array("terza-prima" => [], "terza-seconda" => [], "terza-terza" => []), ); $seconda = $c->getCategoryWithName("seconda"); $seconda[] = "added"; print "cat is: <pre>"; print_r($seconda); print "</pre>"; print "ct is: <pre>"; print_r($c); print "</pre>";

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0060.01316.50
8.3.50.0100.00718.05
8.3.40.0110.00418.85
8.3.30.0110.00318.56
8.3.20.0070.00021.70
8.3.10.0040.00421.89
8.3.00.0030.00519.81
8.2.180.0040.01418.29
8.2.170.0100.01022.96
8.2.160.0070.01020.30
8.2.150.0120.00624.18
8.2.140.0080.00024.66
8.2.130.0040.00420.39
8.2.120.0070.00026.35
8.2.110.0070.00422.31
8.2.100.0120.00017.72
8.2.90.0080.00019.17
8.2.80.0000.00817.97
8.2.70.0040.00417.73
8.2.60.0000.00817.93
8.2.50.0060.00318.10
8.2.40.0050.00220.42
8.2.30.0050.00219.33
8.2.20.0060.00318.13
8.2.10.0060.00318.13
8.2.00.0070.00018.11
8.1.280.0070.00725.92
8.1.270.0080.00018.82
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0060.00323.79
8.1.230.0090.00322.12
8.1.220.0030.00517.74
8.1.210.0000.00818.77
8.1.200.0030.00617.35
8.1.190.0050.00517.38
8.1.180.0000.00718.10
8.1.170.0040.00418.39
8.1.160.0070.00019.07
8.1.150.0000.00818.90
8.1.140.0040.00419.59
8.1.130.0030.00318.91
8.1.120.0040.00417.48
8.1.110.0080.00017.38
8.1.100.0050.00317.43
8.1.90.0030.00517.43
8.1.80.0060.00317.42
8.1.70.0060.00317.43
8.1.60.0000.00817.52
8.1.50.0000.00817.54
8.1.40.0030.00617.54
8.1.30.0040.00417.52
8.1.20.0040.00417.64
8.1.10.0020.00517.59
8.1.00.0090.00317.57
8.0.300.0080.00018.77
8.0.290.0070.00016.75
8.0.280.0000.00718.46
8.0.270.0070.00017.30
8.0.260.0000.00618.96
8.0.250.0070.00016.90
8.0.240.0040.00416.92
8.0.230.0050.00316.93
8.0.220.0030.00516.78
8.0.210.0030.00316.88
8.0.200.0000.00816.86
8.0.190.0030.00516.96
8.0.180.0040.00416.82
8.0.170.0040.00416.97
8.0.160.0020.00517.01
8.0.150.0030.00516.85
8.0.140.0080.00016.86
8.0.130.0000.00613.36
8.0.120.0030.00516.90
8.0.110.0040.00416.92
8.0.100.0000.00716.76
8.0.90.0070.00016.74
8.0.80.0090.00616.95
8.0.70.0040.00416.91
8.0.60.0030.00516.78
8.0.50.0080.00016.95
8.0.30.0090.00617.07
8.0.20.0150.01317.40
8.0.10.0040.00416.92
8.0.00.0080.01116.71
7.4.330.0050.00015.55
7.4.320.0030.00316.61
7.4.300.0030.00316.46
7.4.290.0000.00816.65
7.4.280.0050.00316.56
7.4.270.0030.00316.67
7.4.260.0030.00316.59
7.4.250.0080.00016.61
7.4.240.0000.00816.67
7.4.230.0030.00316.36
7.4.220.0090.00916.71
7.4.210.0070.01416.71
7.4.200.0070.00016.63
7.4.160.0080.01116.46
7.4.150.0090.00917.40
7.4.140.0090.00917.86
7.4.130.0000.01816.57
7.4.120.0130.00716.63
7.4.110.0110.00616.50
7.4.100.0070.01316.49
7.4.90.0130.00516.64
7.4.80.0150.01119.39
7.4.70.0120.00416.29
7.4.60.0120.00816.63
7.4.50.0060.00916.57
7.4.40.0030.01216.54
7.4.30.0160.00316.54
7.4.00.0130.00514.69
7.3.330.0000.00513.38
7.3.320.0000.00513.24
7.3.310.0030.00316.40
7.3.300.0040.00416.38
7.3.290.0070.00816.32
7.3.280.0080.00916.38
7.3.270.0150.00317.40
7.3.260.0080.00916.42
7.3.250.0100.01016.44
7.3.240.0080.01216.41
7.3.230.0100.01316.29
7.3.210.0030.01316.47
7.3.200.0140.01216.61
7.3.190.0090.00916.42
7.3.180.0080.00816.30
7.3.170.0140.00316.41
7.3.160.0070.01016.56
7.3.120.0070.01314.92
7.3.110.0040.01514.75
7.3.100.0100.00714.55
7.3.90.0000.01114.79
7.3.80.0030.00614.71
7.3.70.0070.00714.59
7.3.60.0060.00314.81
7.3.50.0000.01114.64
7.3.40.0100.00614.72
7.3.30.0030.00614.77
7.3.20.0060.00616.77
7.3.10.0100.00616.38
7.3.00.0070.01016.70
7.2.330.0120.00616.73
7.2.320.0130.00616.75
7.2.310.0000.01816.82
7.2.300.0040.01516.56
7.2.290.0030.01316.54
7.2.250.0070.00715.21
7.2.240.0040.01515.20
7.2.230.0040.01114.77
7.2.220.0090.00615.24
7.2.210.0120.00315.34
7.2.200.0040.00814.82
7.2.190.0000.01314.96
7.2.180.0030.00715.10
7.2.170.0080.00814.69
7.2.60.0140.00016.83
7.2.50.0000.01316.89
7.1.330.0090.00615.83
7.1.320.0030.01015.97
7.1.310.0070.00315.70
7.1.300.0030.00915.68
7.1.290.0080.00415.80
7.1.280.0130.00316.00
7.1.270.0030.01215.88
7.1.260.0070.00715.60
7.1.200.0040.00815.90
7.1.70.0030.00717.28
7.1.60.0770.01333.24
7.1.50.0770.01332.96
7.1.40.0930.00332.49
7.1.30.1400.01032.73
7.1.20.1030.01032.93
7.1.10.0830.01014.71
7.1.00.0770.00014.82
7.0.200.0900.00714.88
7.0.190.0930.01014.64
7.0.180.0730.00714.35
7.0.170.1870.01314.40
7.0.160.1300.01014.38
7.0.150.0230.01714.57
7.0.140.0000.01314.59
7.0.130.0730.01014.78
7.0.120.0300.01314.63
7.0.110.0130.01714.56
7.0.100.0100.00714.59
7.0.90.0100.00714.50
7.0.80.0130.01014.65
7.0.70.0070.00714.44
7.0.60.0630.01314.26
7.0.50.0100.00714.40
7.0.40.0130.01714.61
7.0.30.0130.01714.58
7.0.20.0830.01014.51
7.0.10.0870.01014.55
7.0.00.0800.00714.57

preferences:
60.33 ms | 401 KiB | 5 Q