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($tree, $id) { $current = $tree[$id]; $parent_id = $current === NULL ? "NULL" : $current; $parents = array(); $parents[] = $parent_id; while (isset($tree[$parent_id])) { $current = $tree[$parent_id]; $parent_id = $current === NULL ? "NULL" : $current; $parents[] = $parent_id; } echo implode(" > ", array_reverse($parents)); } $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.60.0120.00316.50
8.3.50.0140.00522.01
8.3.40.0040.01118.97
8.3.30.0000.01918.89
8.3.20.0080.00020.22
8.3.10.0070.00023.54
8.3.00.0060.00319.25
8.2.180.0070.01118.02
8.2.170.0110.00322.96
8.2.160.0130.00020.34
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0030.01226.16
8.2.120.0040.00422.08
8.2.110.0000.01122.25
8.2.100.0110.00017.91
8.2.90.0050.00319.13
8.2.80.0030.00617.97
8.2.70.0040.00417.63
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0000.00818.09
8.2.30.0000.00718.07
8.2.20.0050.00217.75
8.2.10.0070.00017.99
8.2.00.0060.00317.75
8.1.280.0180.00425.92
8.1.270.0000.00823.98
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0000.01023.74
8.1.230.0060.00619.10
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.23
8.1.190.0040.00417.39
8.1.180.0060.00318.10
8.1.170.0000.00818.37
8.1.160.0000.00722.02
8.1.150.0050.00218.53
8.1.140.0000.00717.31
8.1.130.0000.00717.88
8.1.120.0080.00017.38
8.1.110.0040.00417.30
8.1.100.0030.00517.40
8.1.90.0040.00417.33
8.1.80.0050.00317.33
8.1.70.0000.00717.31
8.1.60.0040.00417.58
8.1.50.0040.00417.50
8.1.40.0000.00717.41
8.1.30.0040.00417.61
8.1.20.0040.00417.69
8.1.10.0080.00017.64
8.1.00.0070.00017.53
8.0.300.0000.00818.77
8.0.290.0060.00317.01
8.0.280.0030.00318.36
8.0.270.0000.00717.14
8.0.260.0070.00017.27
8.0.250.0030.00316.97
8.0.240.0030.00316.84
8.0.230.0000.00716.88
8.0.220.0000.00716.82
8.0.210.0040.00416.84
8.0.200.0030.00316.80
8.0.190.0070.00016.79
8.0.180.0050.00216.83
8.0.170.0050.00316.71
8.0.160.0000.00716.71
8.0.150.0040.00416.85
8.0.140.0080.00016.80
8.0.130.0030.00313.23
8.0.120.0030.00516.84
8.0.110.0030.00516.82
8.0.100.0000.00816.85
8.0.90.0000.00816.84
8.0.80.0090.00616.84
8.0.70.0050.00216.81
8.0.60.0000.00816.86
8.0.50.0040.00416.80
8.0.30.0160.00517.10
8.0.20.0170.00817.40
8.0.10.0000.00716.81
8.0.00.0130.00816.86
7.4.330.0060.00015.00
7.4.320.0030.00316.59
7.4.300.0060.00016.62
7.4.290.0060.00316.45
7.4.280.0070.00016.62
7.4.270.0030.00316.66
7.4.260.0000.00716.52
7.4.250.0000.00716.55
7.4.240.0030.00316.53
7.4.230.0050.00216.45
7.4.220.0090.00916.55
7.4.210.0090.00716.58
7.4.200.0040.00416.59
7.4.190.0040.00416.38
7.4.160.0040.01216.60
7.4.150.0120.00617.40
7.4.140.0100.00817.86
7.4.130.0120.00716.50
7.4.120.0110.00516.54
7.4.110.0120.00616.37
7.4.100.0000.01616.46
7.4.90.0070.01016.64
7.4.80.0150.00619.39
7.4.70.0110.00616.45
7.4.60.0080.00816.44
7.4.50.0000.00816.41
7.4.40.0090.00622.77
7.4.30.0060.00916.43
7.4.10.0130.00615.17
7.4.00.0090.00715.01
7.3.330.0060.00013.23
7.3.320.0000.00613.23
7.3.310.0080.00016.42
7.3.300.0030.00316.30
7.3.290.0030.01416.34
7.3.280.0030.01316.35
7.3.270.0110.00617.40
7.3.260.0150.00416.44
7.3.250.0130.00916.38
7.3.240.0130.00716.36
7.3.230.0070.01116.69
7.3.210.0060.01016.67
7.3.200.0070.01419.39
7.3.190.0100.00716.53
7.3.180.0090.00616.63
7.3.170.0110.00716.53
7.3.160.0040.01216.39
7.3.130.0070.01014.95
7.3.120.0070.00814.89
7.3.110.0030.01615.12
7.3.100.0090.00614.68
7.3.90.0060.00914.82
7.3.80.0150.00014.75
7.3.70.0000.01414.97
7.3.60.0040.01114.94
7.3.50.0030.01714.89
7.3.40.0130.00014.96
7.3.30.0060.00914.71
7.3.20.0070.01016.62
7.3.10.0090.00016.50
7.3.00.0040.01216.85
7.2.330.0060.01216.55
7.2.320.0070.01716.83
7.2.310.0060.01016.76
7.2.300.0030.01316.59
7.2.290.0070.01016.80
7.2.260.0070.01315.12
7.2.250.0070.01115.13
7.2.240.0040.00814.71
7.2.230.0030.01315.01
7.2.220.0130.00615.20
7.2.210.0070.00715.32
7.2.200.0040.01114.95
7.2.190.0070.00715.07
7.2.180.0030.01014.98
7.2.170.0060.00615.25
7.2.160.0060.00314.91
7.2.150.0040.01116.88
7.2.140.0060.01016.72
7.2.130.0040.01216.90
7.2.120.0090.00616.90
7.2.110.0030.00616.84
7.2.100.0000.01416.93
7.2.90.0140.00317.01
7.2.80.0040.01017.13
7.2.70.0040.01117.09
7.2.60.0080.00416.87
7.2.50.0040.00816.77
7.2.40.0110.00416.82
7.2.30.0000.01416.70
7.2.20.0120.00316.87
7.2.10.0000.01317.03
7.2.00.0080.00518.08
7.1.330.0070.00315.89
7.1.320.0100.00315.79
7.1.310.0030.01015.61
7.1.300.0070.01415.85
7.1.290.0070.00715.90
7.1.280.0030.01015.90
7.1.270.0070.00715.70
7.1.260.0070.01015.71
7.1.250.0110.00015.82
7.1.240.0040.01415.69
7.1.230.0000.01015.74
7.1.220.0090.00615.96
7.1.210.0030.00715.56
7.1.200.0020.01315.65
7.1.190.0070.00315.80
7.1.180.0000.01415.94
7.1.170.0130.00315.86
7.1.160.0000.01215.84
7.1.150.0040.01115.86
7.1.140.0100.00715.84
7.1.130.0130.00015.75
7.1.120.0060.00915.91
7.1.110.0000.01115.98
7.1.100.0040.00816.85
7.1.90.0120.00915.92
7.1.80.0060.00315.80
7.1.70.0080.00616.53
7.1.60.0100.01017.71
7.1.50.0050.00716.31
7.1.40.0000.01215.69
7.1.30.0060.00915.77
7.1.20.0030.00615.88
7.1.10.0090.00615.81
7.1.00.0050.04219.12
7.0.330.0100.00315.25
7.0.320.0080.00615.54
7.0.310.0000.01715.39
7.0.300.0030.01015.36
7.0.290.0030.01315.27
7.0.280.0030.01315.50
7.0.270.0030.00615.28
7.0.260.0030.00915.30
7.0.250.0030.01015.44
7.0.240.0090.00015.50
7.0.230.0060.00915.42
7.0.220.0060.00315.38
7.0.210.0030.00915.60
7.0.200.0050.00715.14
7.0.190.0030.00715.57
7.0.180.0070.00715.40
7.0.170.0030.01315.23
7.0.160.0000.01015.45
7.0.150.0000.01015.43
7.0.140.0030.04218.80
7.0.130.0050.00515.48
7.0.120.0040.00415.63
7.0.110.0430.04017.70
7.0.100.0500.04217.67
7.0.90.0140.03417.70
7.0.80.0390.04017.66
7.0.70.0470.04017.72
7.0.60.0460.04017.68
7.0.50.0410.03917.77
7.0.40.0100.03716.59
7.0.30.0130.03716.47
7.0.20.0150.04016.68
7.0.10.0030.03416.59
7.0.00.0050.04616.54
5.6.400.0030.01014.08
5.6.390.0060.00914.51
5.6.380.0100.00314.67
5.6.370.0070.00714.79
5.6.360.0070.00713.92
5.6.350.0040.00714.44
5.6.340.0090.00614.57
5.6.330.0000.01114.15
5.6.320.0090.00614.33
5.6.310.0040.00814.82
5.6.300.0000.00814.87
5.6.290.0030.00914.06
5.6.280.0050.04117.71
5.6.270.0070.00714.48
5.6.260.0080.02617.57
5.6.250.0050.02917.60
5.6.240.0110.04117.51
5.6.230.0050.04117.69
5.6.220.0110.04017.44
5.6.210.0120.03317.59
5.6.200.0100.04117.43
5.6.190.0050.02817.54
5.6.180.0080.04317.53
5.6.170.0090.03917.52
5.6.160.0030.04217.52
5.6.150.0050.04617.79
5.6.140.0060.04517.65
5.6.130.0070.04417.40
5.6.120.0030.03517.40
5.6.110.0060.04517.77
5.6.100.0050.04017.43
5.6.90.0070.04217.51
5.6.80.0100.04017.36
5.6.70.0050.03117.21
5.6.60.0110.04017.25
5.6.50.0050.03717.24
5.6.40.0150.03217.05
5.6.30.0050.04717.28
5.6.20.0150.03517.26
5.6.10.0070.03917.25
5.6.00.0120.03717.21
5.5.380.0020.04517.44
5.5.370.0140.03717.49
5.5.360.0030.04817.57
5.5.350.0100.04017.50
5.5.340.0080.04017.70
5.5.330.0050.03317.64
5.5.320.0080.04217.58
5.5.310.0120.03717.65
5.5.300.0050.04017.87
5.5.290.0030.04417.43
5.5.280.0100.03917.49
5.5.270.0070.04817.62
5.5.260.0090.04417.87
5.5.250.0070.04317.59
5.5.240.0030.04417.21
5.5.230.0130.04117.30
5.5.220.0050.04117.37
5.5.210.0030.04517.25
5.5.200.0070.03317.22
5.5.190.0070.04117.28
5.5.180.0100.04217.40
5.5.170.0080.00414.32
5.5.160.0070.04017.27
5.5.150.0140.03517.26
5.5.140.0080.03917.24
5.5.130.0020.04417.31
5.5.120.0090.03717.34
5.5.110.0020.04817.25
5.5.100.0120.03517.21
5.5.90.0060.04317.28
5.5.80.0100.03317.19
5.5.70.0100.03817.16
5.5.60.0030.04717.26
5.5.50.0050.04317.39
5.5.40.0060.02517.26
5.5.30.0110.03317.33
5.5.20.0050.02517.26
5.5.10.0050.04317.14
5.5.00.0070.04317.19
5.4.450.0080.04015.41
5.4.440.0100.04215.51
5.4.430.0030.04315.29
5.4.420.0050.03815.35
5.4.410.0100.03815.28
5.4.400.0050.04714.99
5.4.390.0050.04015.21
5.4.380.0070.02815.28
5.4.370.0030.04415.29
5.4.360.0050.04215.22
5.4.350.0070.03915.36
5.4.340.0030.04115.24
5.4.330.0000.00911.16
5.4.320.0100.03815.05
5.4.310.0060.03515.04
5.4.300.0070.04015.07
5.4.290.0030.03515.18
5.4.280.0100.04015.17
5.4.270.0010.04315.15
5.4.260.0070.03315.10
5.4.250.0080.03615.22
5.4.240.0040.02215.12
5.4.230.0060.02514.97
5.4.220.0040.04015.05
5.4.210.0020.04015.03
5.4.200.0150.03014.91
5.4.190.0030.03815.27
5.4.180.0050.04415.09
5.4.170.0030.03915.12
5.4.160.0100.03015.17
5.4.150.0050.04015.12
5.4.140.0060.02314.02
5.4.130.0050.02413.93
5.4.120.0020.03513.88
5.4.110.0050.02213.84
5.4.100.0080.02914.06
5.4.90.0030.03513.80
5.4.80.0110.03313.85
5.4.70.0030.04213.88
5.4.60.0020.04414.00
5.4.50.0040.03813.92
5.4.40.0050.03813.83
5.4.30.0030.04213.62
5.4.20.0040.03113.88
5.4.10.0030.02813.94
5.4.00.0080.03813.70
5.3.290.0050.04312.51
5.3.280.0100.03512.53
5.3.270.0060.01812.58
5.3.260.0050.03912.38
5.3.250.0050.03612.52
5.3.240.0050.03812.34
5.3.230.0060.01812.55
5.3.220.0020.04212.33
5.3.210.0060.03812.27
5.3.200.0070.03712.33
5.3.190.0040.03712.51
5.3.180.0050.04012.64
5.3.170.0050.04412.51
5.3.160.0060.03512.39
5.3.150.0030.04412.36
5.3.140.0050.04212.39
5.3.130.0090.04212.47
5.3.120.0030.04012.46
5.3.110.0050.03912.36
5.3.100.0030.03712.22
5.3.90.0060.04112.21
5.3.80.0080.03712.16
5.3.70.0020.04512.19
5.3.60.0090.03712.17
5.3.50.0050.04212.16
5.3.40.0030.02812.03
5.3.30.0050.04012.12
5.3.20.0030.04211.89
5.3.10.0030.04011.86
5.3.00.0070.03811.98
5.2.170.0070.06012.95
5.2.160.0000.06012.95
5.2.150.0030.06312.95
5.2.140.0070.06012.95
5.2.130.0070.03712.95
5.2.120.0070.05312.95
5.2.110.0170.04712.95
5.2.100.0070.06312.95
5.2.90.0030.03712.95
5.2.80.0100.05712.95
5.2.70.0070.04312.95
5.2.60.0070.05712.95
5.2.50.0030.05312.95
5.2.40.0070.05012.95
5.2.30.0070.06012.95
5.2.20.0000.06012.95
5.2.10.0030.05712.95
5.2.00.0030.06012.95
5.1.60.0000.03012.95
5.1.50.0070.05012.95
5.1.40.0000.02712.95
5.1.30.0030.05712.95
5.1.20.0030.04312.95
5.1.10.0030.04012.95
5.1.00.0030.06012.95
5.0.50.0030.04712.95
5.0.40.0070.01712.95
5.0.30.0030.06312.95
5.0.20.0000.04312.95
5.0.10.0030.03312.95
5.0.00.0070.05712.95
4.4.90.0000.04012.95
4.4.80.0000.04012.95
4.4.70.0000.03712.95
4.4.60.0030.03312.95
4.4.50.0000.03712.95
4.4.40.0030.04712.95
4.4.30.0000.03712.95
4.4.20.0000.03712.95
4.4.10.0070.03012.95
4.4.00.0000.02712.95
4.3.110.0070.02312.95
4.3.100.0030.03012.95
4.3.90.0000.02012.95
4.3.80.0000.05312.95
4.3.70.0100.02712.95
4.3.60.0000.03312.95
4.3.50.0000.03312.95
4.3.40.0000.05712.95
4.3.30.0030.02312.95
4.3.20.0000.03712.95
4.3.10.0070.03312.95
4.3.00.0000.03712.95

preferences:
41.34 ms | 401 KiB | 5 Q