3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $lastId) { $gTree = []; if ($id != $lastId) { $gTree[] = $id; if ( isset($treeByCat[ $id ]) && count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ], $id), $gTree); if ( isset($treeByParent[ $id ]) && count($treeByParent[ $id ]) > 0 ) { foreach ($treeByParent[ $id ] as $cat) { $gTree = array_merge( getTree($treeByParent, $treeByCat, $cat, $id), $gTree); } } return $gTree; } } function display_parent_nodes($data, $id) { $tree = array( "parents" => array(), "children" => array(), "full" => array() ); $current = $data[$id]; $parent_id = $current === NULL ? "NULL" : $current; $childIds = array($id); $tree['parents'][] = $parent_id; while (isset($data[$parent_id])) { $current = $data[$parent_id]; $parent_id = $current === NULL ? "NULL" : $current; $tree['parents'][] = $parent_id; } //echo implode(" > ", array_reverse($tree['parents'])); while ( count($childIds) > 0 ) { foreach($childIds as $child) { $children = array_keys($data, $child); print_r($children); foreach ($children as $ch) { $tree['children'][] = $ch; } $childIds = $children; } } //echo "\n". implode(" > ", $tree['children']); $tree['full'] = array_merge(array_reverse($tree['parents']), $tree['children']); echo implode(" > ", $tree['full']); } $treeByParent = array( 0 => array(1, 2), 1 => array(3, 7), 3 => array(4), 4 => array(5), 5 => array(6, 8) ); $treeByCat = array( 1 => 0, 2 => 0, 3 => 1, 7 => 1, 4 => 3, 5 => 4, 6 => 5, 8 => 5 ); print_r( display_parent_nodes($treeByCat, 4) ); //print_r( getTree($treeByParent, $treeByCat, 4, 0) );

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.70.0110.00418.56
8.3.60.0100.00716.63
8.3.50.0170.00321.97
8.3.40.0150.00018.84
8.3.30.0100.00319.21
8.3.20.0070.00020.35
8.3.10.0040.00423.48
8.3.00.0030.00519.38
8.2.180.0100.00318.16
8.2.170.0150.00622.96
8.2.160.0070.00720.52
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0070.01126.16
8.2.120.0050.00322.17
8.2.110.0080.00022.11
8.2.100.0060.00617.78
8.2.90.0030.00519.17
8.2.80.0040.00418.05
8.2.70.0080.00017.50
8.2.60.0060.00318.05
8.2.50.0060.00318.07
8.2.40.0060.00318.28
8.2.30.0040.00418.17
8.2.20.0050.00317.82
8.2.10.0040.00418.14
8.2.00.0030.00717.74
8.1.280.0030.01425.92
8.1.270.0040.00423.71
8.1.260.0030.00526.35
8.1.250.0070.00028.09
8.1.240.0000.00823.83
8.1.230.0110.00319.16
8.1.220.0060.00317.79
8.1.210.0050.00318.77
8.1.200.0040.00417.13
8.1.190.0050.00317.52
8.1.180.0000.00918.10
8.1.170.0040.00418.69
8.1.160.0040.00422.08
8.1.150.0040.00418.65
8.1.140.0000.00717.34
8.1.130.0000.00717.71
8.1.120.0000.00817.35
8.1.110.0050.00317.40
8.1.100.0040.00417.49
8.1.90.0050.00217.54
8.1.80.0000.00717.46
8.1.70.0030.00517.34
8.1.60.0040.00417.60
8.1.50.0050.00517.41
8.1.40.0000.00717.58
8.1.30.0090.00017.62
8.1.20.0000.00817.67
8.1.10.0040.00417.44
8.1.00.0000.00817.54
8.0.300.0000.00818.77
8.0.290.0000.00717.18
8.0.280.0030.00318.37
8.0.270.0070.00017.21
8.0.260.0030.00317.23
8.0.250.0000.00616.95
8.0.240.0070.00016.98
8.0.230.0000.00716.97
8.0.220.0040.00416.87
8.0.210.0060.00316.80
8.0.200.0000.00616.93
8.0.190.0000.00716.90
8.0.180.0040.00416.88
8.0.170.0080.00016.80
8.0.160.0040.00416.89
8.0.150.0040.00416.89
8.0.140.0070.00016.93
8.0.130.0030.00313.43
8.0.120.0030.00516.75
8.0.110.0000.00816.84
8.0.100.0040.00416.77
8.0.90.0000.00816.78
8.0.80.0060.01616.88
8.0.70.0050.00316.86
8.0.60.0040.00416.98
8.0.50.0000.00716.85
8.0.30.0120.00816.86
8.0.20.0170.00517.40
8.0.10.0000.00717.05
8.0.00.0100.00816.79
7.4.330.0050.00015.00
7.4.320.0060.00016.62
7.4.300.0050.00216.63
7.4.290.0070.00016.67
7.4.280.0000.00716.53
7.4.270.0000.00816.39
7.4.260.0070.00016.58
7.4.250.0000.00716.49
7.4.240.0040.00516.56
7.4.230.0000.00716.63
7.4.220.0090.01016.56
7.4.210.0060.01116.52
7.4.200.0030.00316.41
7.4.190.0050.00216.68
7.4.160.0090.00616.31
7.4.150.0090.00917.40
7.4.140.0060.01617.86
7.4.130.0110.00616.44
7.4.120.0100.00716.51
7.4.110.0100.00716.39
7.4.100.0030.01316.70
7.4.90.0100.00616.57
7.4.80.0100.00719.39
7.4.70.0100.00716.36
7.4.60.0070.01016.47
7.4.50.0000.00516.59
7.4.40.0000.01322.77
7.4.30.0140.00416.52
7.4.10.0000.01915.16
7.4.00.0060.00914.78
7.3.330.0030.00313.25
7.3.320.0000.00613.35
7.3.310.0040.00416.42
7.3.300.0000.00716.25
7.3.290.0080.00616.33
7.3.280.0090.00816.37
7.3.270.0120.00817.40
7.3.260.0090.00816.41
7.3.250.0140.00516.44
7.3.240.0210.00316.34
7.3.230.0150.00616.40
7.3.210.0110.00716.51
7.3.200.0060.01219.39
7.3.190.0160.00016.59
7.3.180.0030.01716.43
7.3.170.0040.01116.46
7.3.160.0140.00316.58
7.3.130.0090.00614.89
7.3.120.0090.00814.92
7.3.110.0040.01614.59
7.3.100.0060.00914.89
7.3.90.0060.00615.05
7.3.80.0030.01014.91
7.3.70.0060.00614.64
7.3.60.0030.00914.63
7.3.50.0100.00314.90
7.3.40.0100.00315.06
7.3.30.0030.01314.88
7.3.20.0070.00716.55
7.3.10.0120.00816.48
7.3.00.0090.00916.36
7.2.330.0160.00616.80
7.2.320.0110.01116.66
7.2.310.0060.01216.54
7.2.300.0080.01216.92
7.2.290.0060.01616.97
7.2.260.0000.01914.98
7.2.250.0090.00915.29
7.2.240.0120.00314.77
7.2.230.0070.00715.17
7.2.220.0000.01215.06
7.2.210.0070.00715.36
7.2.200.0060.00615.13
7.2.190.0040.00815.15
7.2.180.0000.01414.94
7.2.170.0120.00315.14
7.2.160.0080.00815.27
7.2.150.0080.00817.11
7.2.140.0120.00316.93
7.2.130.0090.00816.87
7.2.120.0080.00716.72
7.2.110.0060.01116.60
7.2.100.0080.01116.84
7.2.90.0080.00916.73
7.2.80.0100.00616.86
7.2.70.0080.00716.90
7.2.60.0120.00716.72
7.2.50.0100.00716.71
7.2.40.0080.01016.78
7.2.30.0120.00416.93
7.2.20.0140.00416.58
7.2.10.0100.00516.64
7.2.00.0050.01017.46
7.1.330.0130.00315.75
7.1.320.0110.00015.88
7.1.310.0000.01315.92
7.1.300.0000.01415.84
7.1.290.0040.01116.03
7.1.280.0000.01115.81
7.1.270.0130.00015.85
7.1.260.0090.00315.88
7.1.250.0050.00815.55
7.1.240.0090.00615.75
7.1.230.0070.01015.76
7.1.220.0000.01515.76
7.1.210.0030.01015.91
7.1.200.0040.00815.72
7.1.190.0040.01215.70
7.1.180.0070.00415.84
7.1.170.0030.00615.56
7.1.160.0000.01015.94
7.1.150.0000.00816.02
7.1.140.0100.00015.68
7.1.130.0000.01315.64
7.1.120.0060.00615.86
7.1.110.0030.01215.73
7.1.100.0070.00516.72
7.1.90.0000.01115.63
7.1.80.0060.00915.68
7.1.70.0070.00516.38
7.1.60.0050.00516.38
7.1.50.0060.01116.47
7.1.40.0060.00615.48
7.1.30.0090.00615.91
7.1.20.0060.00915.75
7.1.10.0060.00615.69
7.1.00.0080.03619.05
7.0.330.0050.00315.45
7.0.320.0140.00315.42
7.0.310.0040.00815.34
7.0.300.0070.00315.35
7.0.290.0000.01115.47
7.0.280.0080.00315.18
7.0.270.0030.00915.39
7.0.260.0100.00315.31
7.0.250.0070.00715.56
7.0.240.0000.01115.40
7.0.230.0070.00715.45
7.0.220.0040.00815.36
7.0.210.0050.00515.37
7.0.200.0110.00616.16
7.0.190.0090.00015.56
7.0.180.0030.00915.56
7.0.170.0070.01015.48
7.0.160.0040.00715.12
7.0.150.0030.00915.56
7.0.140.0030.03818.66
7.0.130.0030.01015.39
7.0.120.0060.00915.08
7.0.110.0070.00315.44
7.0.100.0030.00615.15
7.0.90.0040.01115.39
7.0.80.0060.00315.13
7.0.70.0090.00615.11
7.0.60.0020.04417.82
7.0.50.0070.03916.81
7.0.40.0070.03416.83
7.0.30.0130.03216.78
7.0.20.0130.03116.81
7.0.10.0050.03016.86
7.0.00.0050.03216.84
5.6.400.0100.00314.33
5.6.390.0080.00414.68
5.6.380.0000.01114.41
5.6.370.0030.01014.85
5.6.360.0040.00814.71
5.6.350.0080.00414.50
5.6.340.0100.00614.29
5.6.330.0060.00614.25
5.6.320.0000.00814.61
5.6.310.0050.00314.48
5.6.300.0070.00714.52
5.6.290.0090.00614.46
5.6.280.0020.04317.83
5.6.270.0080.00414.63
5.6.260.0060.00614.47
5.6.250.0000.01114.76
5.6.240.0100.00314.54
5.6.230.0030.00614.48
5.6.220.0080.00414.56
5.6.210.0120.03817.59
5.6.200.0020.04016.27
5.6.190.0080.04317.57
5.6.180.0150.04217.35
5.6.170.0190.03717.41
5.6.160.0090.03717.46
5.6.150.0070.02716.27
5.6.140.0080.04216.34
5.6.130.0100.03716.28
5.6.120.0050.04517.85
5.6.110.0080.04017.68
5.6.100.0080.03717.60
5.6.90.0030.02417.79
5.6.80.0130.03517.45
5.6.70.0520.02217.37
5.6.60.0030.00914.48
5.6.50.0070.01014.62
5.6.40.0040.01114.46
5.6.30.0090.00014.47
5.6.20.0030.01314.65
5.6.10.0000.01614.62
5.6.00.0040.00814.23
5.5.380.0000.00814.41
5.5.370.0060.01214.16
5.5.360.0030.00714.60
5.5.350.0090.03717.35
5.5.340.0080.03516.14
5.5.330.0060.02317.46
5.5.320.0180.03317.25
5.5.310.0170.02717.48
5.5.300.0080.04316.15
5.5.290.0070.03716.20
5.5.280.0080.04117.54
5.5.270.0030.04817.73
5.5.260.0060.02617.53
5.5.250.0080.04317.60
5.5.240.0080.02017.33
5.5.230.0110.00414.31
5.5.220.0030.01014.20
5.5.210.0070.00714.03
5.5.200.0000.01514.49
5.5.190.0070.00414.09
5.5.180.0060.00614.43
5.5.170.0100.00714.54
5.5.160.0110.00414.47
5.5.150.0060.00614.50
5.5.140.0040.01114.27
5.5.130.0080.00414.36
5.5.120.0000.01014.37
5.5.110.0070.00714.20
5.5.100.0030.01014.33
5.5.90.0030.01314.13
5.5.80.0050.00314.25
5.5.70.0070.00714.40
5.5.60.0000.01014.59
5.5.50.0030.00814.36
5.5.40.0000.01514.29
5.5.30.0080.00314.17
5.5.20.0040.00714.35
5.5.10.0090.00614.16
5.5.00.0000.01214.13
5.4.450.0130.02615.35
5.4.440.0430.03515.29
5.4.430.0480.04315.43
5.4.420.0620.03015.37
5.4.410.0400.02715.27
5.4.400.0460.03415.14
5.4.390.0430.02815.34
5.4.380.0210.03015.04
5.4.370.0230.02714.87
5.4.360.0350.02514.84
5.4.350.0270.01814.80
5.4.340.0120.03214.98
5.4.330.0000.00711.42
5.4.320.0040.03011.83
5.4.310.0040.02311.84
5.4.300.0020.02411.81
5.4.290.0050.02911.82
5.4.280.0070.02511.80
5.4.270.0020.02411.86
5.4.260.0060.02511.85
5.4.250.0060.02011.77
5.4.240.0080.02611.70
5.4.230.0060.02011.75
5.4.220.0040.02211.74
5.4.210.0090.02511.71
5.4.200.0040.02311.66
5.4.190.0060.02111.67
5.4.180.0060.02211.73
5.4.170.0060.02111.72
5.4.160.0060.02511.89
5.4.150.0070.03411.88
5.4.140.0060.02211.66
5.4.130.0050.02811.70
5.4.120.0050.02911.50
5.4.110.0060.03911.62
5.4.100.0050.02511.72
5.4.90.0060.03211.72
5.4.80.0140.03111.61
5.4.70.0070.03411.64
5.4.60.0070.02811.47
5.4.50.0080.02611.51
5.4.40.0050.02911.60
5.4.30.0070.03511.69
5.4.20.0060.02311.67
5.4.10.0060.02311.71
5.4.00.0060.02711.42
5.3.290.0050.02111.87
5.3.280.0060.02011.82
5.3.270.0050.04111.83
5.3.260.0040.03111.83
5.3.250.0130.04111.83
5.3.240.0030.03211.83
5.3.230.0070.02711.83
5.3.220.0080.02711.81
5.3.210.0070.02811.81
5.3.200.0080.03611.81
5.3.190.0080.04011.81
5.3.180.0090.02511.81
5.3.170.0040.03011.80
5.3.160.0100.04211.81
5.3.150.0080.01911.81
5.3.140.0040.02311.80
5.3.130.0040.02411.80
5.3.120.0070.02311.80
5.3.110.0050.03111.80
5.3.100.0080.03311.53
5.3.90.0090.02711.51
5.3.80.0040.02611.51
5.3.70.0070.02111.51
5.3.60.0110.02611.50
5.3.50.0080.02011.47
5.3.40.0080.02411.47
5.3.30.0070.02711.45
5.3.20.0040.02811.34
5.3.10.0050.03111.32
5.3.00.0070.03111.31
5.2.170.0080.0499.19
5.2.160.0060.0419.18
5.2.150.0110.0389.18
5.2.140.0050.0549.18
5.2.130.0050.0479.14
5.2.120.0040.0339.14
5.2.110.0060.0319.15
5.2.100.0070.0299.14
5.2.90.0040.0339.14
5.2.80.0060.0329.14
5.2.70.0090.0309.14
5.2.60.0070.0319.09
5.2.50.0060.0329.07
5.2.40.0060.0309.04
5.2.30.0070.0359.02
5.2.20.0100.0259.01
5.2.10.0010.0348.92
5.2.00.0020.0348.78
5.1.60.0070.0258.07
5.1.50.0060.0288.07
5.1.40.0060.0278.05
5.1.30.0090.0278.39
5.1.20.0080.0398.41
5.1.10.0080.0298.14
5.1.00.0050.0288.14
5.0.50.0060.0216.62
5.0.40.0050.0246.49
5.0.30.0060.0346.29
5.0.20.0070.0246.26
5.0.10.0060.0286.24
5.0.00.0080.0316.23
4.4.90.0020.0194.78
4.4.80.0060.0154.75
4.4.70.0030.0174.76
4.4.60.0030.0164.76
4.4.50.0090.0154.77
4.4.40.0050.0264.71
4.4.30.0030.0204.76
4.4.20.0100.0214.84
4.4.10.0020.0244.85
4.4.00.0030.0474.76
4.3.110.0030.0254.67
4.3.100.0030.0154.67
4.3.90.0040.0284.64
4.3.80.0080.0274.59
4.3.70.0040.0354.63
4.3.60.0040.0224.63
4.3.50.0050.0274.63
4.3.40.0050.0344.54
4.3.30.0030.0233.29
4.3.20.0030.0213.26
4.3.10.0000.0253.23
4.3.00.0230.01710.37

preferences:
49.55 ms | 401 KiB | 5 Q