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(); 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.0110.00418.14
8.3.50.0110.00622.06
8.3.40.0140.00718.97
8.3.30.0000.01419.16
8.3.20.0040.00419.96
8.3.10.0000.00823.48
8.3.00.0000.00819.26
8.2.180.0120.00618.41
8.2.170.0040.01122.96
8.2.160.0110.00320.54
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0110.00017.75
8.2.110.0070.00322.20
8.2.100.0070.00417.84
8.2.90.0000.00819.36
8.2.80.0040.00418.05
8.2.70.0030.00517.75
8.2.60.0060.00318.02
8.2.50.0000.00818.07
8.2.40.0000.00818.34
8.2.30.0000.00718.18
8.2.20.0040.00417.76
8.2.10.0000.00818.13
8.2.00.0030.00617.68
8.1.280.0130.00725.92
8.1.270.0060.00323.96
8.1.260.0040.00426.35
8.1.250.0030.00528.09
8.1.240.0060.00323.67
8.1.230.0120.00019.16
8.1.220.0040.00417.80
8.1.210.0050.00518.77
8.1.200.0050.00517.22
8.1.190.0030.00617.39
8.1.180.0000.00818.10
8.1.170.0040.00418.45
8.1.160.0070.00021.85
8.1.150.0000.00718.51
8.1.140.0070.00017.39
8.1.130.0000.00717.82
8.1.120.0070.00017.44
8.1.110.0030.00717.41
8.1.100.0040.00417.37
8.1.90.0040.00417.49
8.1.80.0040.00417.33
8.1.70.0070.00017.25
8.1.60.0040.00417.59
8.1.50.0040.00417.53
8.1.40.0030.00517.48
8.1.30.0040.00417.61
8.1.20.0040.00417.50
8.1.10.0050.00217.59
8.1.00.0030.00517.41
8.0.300.0000.00718.77
8.0.290.0040.00417.05
8.0.280.0000.00718.46
8.0.270.0030.00317.18
8.0.260.0050.00317.26
8.0.250.0030.00317.00
8.0.240.0030.00316.97
8.0.230.0000.00816.90
8.0.220.0000.00716.91
8.0.210.0000.00716.90
8.0.200.0030.00316.91
8.0.190.0050.00316.95
8.0.180.0040.00416.75
8.0.170.0040.00416.89
8.0.160.0050.00316.82
8.0.150.0040.00416.86
8.0.140.0040.00416.85
8.0.130.0030.00313.20
8.0.120.0000.00816.73
8.0.110.0000.00816.87
8.0.100.0000.00716.78
8.0.90.0000.00816.95
8.0.80.0060.00916.72
8.0.70.0040.00416.73
8.0.60.0040.00416.87
8.0.50.0000.00716.90
8.0.30.0070.01217.17
8.0.20.0140.01217.40
8.0.10.0000.00716.78
8.0.00.0070.01216.76
7.4.330.0030.00315.00
7.4.320.0000.00716.54
7.4.300.0000.00616.62
7.4.290.0070.00016.47
7.4.280.0000.00716.61
7.4.270.0000.00816.45
7.4.260.0070.00016.53
7.4.250.0040.00416.47
7.4.240.0040.00316.58
7.4.230.0040.00416.64
7.4.220.0060.01316.65
7.4.210.0050.01116.61
7.4.200.0000.00716.59
7.4.190.0040.00416.68
7.4.160.0040.01116.35
7.4.150.0160.00617.40
7.4.140.0070.01117.86
7.4.130.0090.00816.46
7.4.120.0150.00416.52
7.4.110.0180.00316.55
7.4.100.0070.01016.45
7.4.90.0060.01016.61
7.4.80.0160.00319.39
7.4.70.0090.00616.64
7.4.60.0100.00716.57
7.4.50.0040.00416.37
7.4.40.0090.00622.77
7.4.30.0110.00616.61
7.4.00.0100.00715.01
7.3.330.0000.00513.37
7.3.320.0050.00013.08
7.3.310.0050.00216.26
7.3.300.0000.00716.32
7.3.290.0130.00616.37
7.3.280.0060.00916.37
7.3.270.0130.00317.40
7.3.260.0080.01216.55
7.3.250.0150.00616.59
7.3.240.0090.01216.34
7.3.230.0090.00916.39
7.3.210.0030.01316.58
7.3.200.0150.00419.39
7.3.190.0060.00916.36
7.3.180.0040.01516.62
7.3.170.0000.01516.38
7.3.160.0030.01216.31
7.3.120.0110.00414.78
7.2.330.0100.00716.54
7.2.320.0070.01416.77
7.2.310.0150.00916.80
7.2.300.0090.00916.89
7.2.290.0100.00716.76
7.1.70.0070.00717.19
7.1.60.0120.01219.33
7.1.50.0130.01017.06
7.1.00.0030.07722.30
7.0.200.0150.00614.95
7.0.140.0030.07322.21
7.0.60.0000.05720.01
7.0.50.0100.03317.93
7.0.40.0070.05720.09
7.0.30.0270.08020.20
7.0.20.0300.08020.16
7.0.10.0030.04720.24
7.0.00.0030.05720.27
5.6.280.0100.06720.83
5.6.210.0070.06720.55
5.6.200.0030.06018.17
5.6.190.0000.04720.63
5.6.180.0170.06720.43
5.6.170.0230.04020.45
5.6.160.0100.06020.45
5.6.150.0030.08318.18
5.6.140.0030.06018.17
5.6.130.0030.05018.24
5.6.120.0000.06321.05
5.6.110.0070.08320.97
5.6.100.0130.03720.99
5.6.90.0130.08321.01
5.6.80.0100.04720.45
5.6.70.3430.03720.39
5.5.350.0170.03320.36
5.5.340.0030.05017.98
5.5.330.0070.07720.28
5.5.320.0370.08020.30
5.5.310.0330.07720.19
5.5.300.0000.05717.98
5.5.290.0170.07317.98
5.5.280.0000.04320.88
5.5.270.0070.06020.80
5.5.260.0100.08320.65
5.5.250.0070.07320.59
5.5.240.0100.04320.16
5.4.450.0670.06019.17
5.4.440.0600.06019.17
5.4.430.0130.06019.20
5.4.420.0770.08719.61
5.4.410.0830.06319.46
5.4.400.0830.05718.88
5.4.390.0730.05719.29
5.4.380.0630.06318.75
5.4.370.0330.04318.53
5.4.360.0200.05318.82
5.4.350.0300.05018.57
5.4.340.0330.05018.75
5.4.320.0060.04612.51
5.4.310.0070.04712.50
5.4.300.0070.03612.51
5.4.290.0070.04412.50
5.4.280.0100.03412.38
5.4.270.0080.03812.38
5.4.260.0060.04112.37
5.4.250.0050.04112.37
5.4.240.0100.03412.38
5.4.230.0060.03912.37
5.4.220.0090.03712.37
5.4.210.0110.03712.37
5.4.200.0120.04012.37
5.4.190.0090.03912.36
5.4.180.0120.04712.36
5.4.170.0120.05112.37
5.4.160.0090.04812.37
5.4.150.0060.04112.37
5.4.140.0050.06012.05
5.4.130.0210.05412.04
5.4.120.0080.05211.99
5.4.110.0120.05311.99
5.4.100.0130.04811.99
5.4.90.0100.05611.99
5.4.80.0120.06011.99
5.4.70.0090.05511.99
5.4.60.0090.05711.98
5.4.50.0290.04811.98
5.4.40.0060.04011.98
5.4.30.0070.04011.97
5.4.20.0110.03611.97
5.4.10.0050.04011.97
5.4.00.0060.04111.46
5.3.290.0080.03712.80
5.3.280.0150.04712.71
5.3.270.0100.04512.72
5.3.260.0090.04012.72
5.3.250.0130.03412.71
5.3.240.0040.04312.71
5.3.230.0100.04012.71
5.3.220.0060.04112.68
5.3.210.0080.04312.68
5.3.200.0130.03312.68
5.3.190.0050.04412.68
5.3.180.0080.04112.67
5.3.170.0080.04312.67
5.3.160.0120.04412.67
5.3.150.0090.04012.68
5.3.140.0130.04612.66
5.3.130.0060.04312.66
5.3.120.0100.05012.66
5.3.110.0090.04012.66
5.3.100.0090.04912.11
5.3.90.0100.04712.09
5.3.80.0150.09912.07
5.3.70.0460.08912.07
5.3.60.0100.04912.06
5.3.50.0040.04912.00
5.3.40.0130.04812.00
5.3.30.0100.05611.95
5.3.20.0050.04311.74
5.3.10.0060.04011.71
5.3.00.0100.03911.69
5.2.170.0050.0369.18
5.2.160.0060.0419.18
5.2.150.0040.0329.18
5.2.140.0040.0349.18
5.2.130.0070.0329.14
5.2.120.0070.0419.14
5.2.110.0070.0429.14
5.2.100.0060.0429.14
5.2.90.0080.0319.14
5.2.80.0080.0309.14
5.2.70.0040.0459.14
5.2.60.0060.0339.09
5.2.50.0040.0369.07
5.2.40.0090.0409.04
5.2.30.0080.0289.02
5.2.20.0100.0419.01
5.2.10.0080.0298.92
5.2.00.0040.0368.78
5.1.60.0070.0378.07
5.1.50.0020.0298.07
5.1.40.0070.0308.05
5.1.30.0140.0358.39
5.1.20.0110.0548.41
5.1.10.0040.0438.14
5.1.00.0060.0388.14
5.0.50.0070.0316.61
5.0.40.0070.0276.49
5.0.30.0100.0396.29
5.0.20.0070.0266.26
5.0.10.0050.0306.24
5.0.00.0070.0426.23
4.4.90.0060.0204.78
4.4.80.0060.0224.76
4.4.70.0060.0224.75
4.4.60.0040.0234.75
4.4.50.0040.0244.77
4.4.40.0040.0364.71
4.4.30.0090.0354.76
4.4.20.0050.0264.85
4.4.10.0070.0234.85
4.4.00.0060.0374.76
4.3.110.0090.0734.67
4.3.100.0060.0284.66
4.3.90.0040.0234.64
4.3.80.0080.0354.58
4.3.70.0100.0314.63
4.3.60.0020.0354.62
4.3.50.0050.0234.63
4.3.40.0030.0284.54
4.3.30.0040.0163.28
4.3.20.0040.0153.27
4.3.10.0030.0163.23
4.3.00.0000.03010.37

preferences:
58.48 ms | 400 KiB | 5 Q